Can we generate id from forest admin in MongoDB in string format currently it is generating objectid

Can we generate id from forest admin in MongoDB in string format currently it is generating objectid

Hi @rohit_ja,

I guess it is an ODM question.
Can you share an example of Mongoose schema you’d like to see with id having a string format instead of objectid?

Why do you need such string format?
I am not sure this something actually possible or recommended to do so.

Thanks for your help!

We are using Meteor for website development and forest admin for admin panel When creating a record using Meteor, it generates and stores its own _id in mongoDB as a String eg. “zzyqDeC7t2xdtbSw6”.But while creating a record using forest admin it uses Object Id.Because of this Meteor Website cannot read that record.

Hi @rohit_ja,

Could I take a look at the model generated by lumber? (you can find it here: <path_to_your_project>/models/<your_model_name>.js)

// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models

const mongoose = require('mongoose');

// This section contains the properties of your model, mapped to your collection's properties.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model

const schema = mongoose.Schema({
  '_id': String,
  'name': String,
  'color': String,
}, {
  timestamps: false,
});

module.exports = mongoose.model('causes', schema, 'Causes');

Hey @rohit_ja,
Could you try to do something like:

const mongoose = require('mongoose');

// This section contains the properties of your model, mapped to your collection's properties.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model

const schema = mongoose.Schema({
  '_id': {
    type: String,
    default: () => {
      // Generate my meteor id
   },
  'name': String,
  'color': String,
}, {
  timestamps: false,
});

module.exports = mongoose.model('causes', schema, 'Causes');

Hello @Vince can you tell me what will come over here default: () => {
// Generate my meteor id
}, as meteor website is seperate and I am creating it from forest admin.

This was your question, no? A way to generate an _id like you want. If there is no specific format required you could for example generate a uuid

Hey @rohit_ja,

We will consider this subject closed if there is no reply from you in the following week. Please let us know if your issue was fixed :pray: