Referencing manually and DBRef

Hello everyone!

I want to appreciate the forest team and community for their continuous support with my previous queries.

I am facing two issues here and would really appreciate forest team’s assistance on it.

Firstly, I am using “forest-express-mongoose”: “^8.0.0” with javascript and plugging multiple databases as you can see. I am trying to create a reference from one schema, in one database to another schema in another database. For example, create a reference between payments and organizations.


Please let me know if there is a specific solution to do this.

Hi @tanish :wave: unfortunately it is not possible natively from mongoose model today, BUT I have a solution for you!
You can create a SmartRelationShip like below.
models :point_down:

const schema = Mongoose.Schema({
  'name': String,
}, {
  timestamps: false,
mongoose.model('user', schema, 'user');

const schema = Mongoose.Schema({
  'owner': ObjectId // ref on user model
}, {
  timestamps: false,
mongoose.model('cars', schema, 'cars');

forest/cars.js :point_down:

collection('cars', {
  actions: [],
  fields: [{
    field: 'user',
    reference: 'user._id',
    get: (record) => {
      return { _id: record.owner };
  segments: [],
  fieldsToFlatten: [],

Let me know if that help.

I m gonna add your request on our product board to handle this on the mongoose model side directly.

1 Like

Thanks! I will try that.

There’s one more thing. My team is using Java Springboot for the the main project and I am creating a admin panel around it. They have used DbRef for some fields for referencing. Is there any way I can incorporate that too?

Sorry for the question but, what is? :sweat_smile: