Failing Many-to-One Relationship from Mongoose

Feature(s) impacted

I have a mongoose datasource connected. One collection is called ‘lawyers’, the other ‘offices’. The offices schema contains the following line:

lawyers: { type: [Mongoose.Schema.Types.ObjectId], ref: 'lawyers' },

Observed behavior

Everything appears on the dashboard as it should. But the offices have no related reference for lawyers. Instead, this field seems to be configured as a Text input (array).

Expected behavior

From the docs: “You may have noticed that relationships within a data source are configured out of the box, so you won’t need to define those.”

I expect this relationship to work out of the box. Is that correct? Or did I screw up the configuration?


  • Project name: jurata-2
  • Team name: jurata
  • Environment name: Development
  • Agent (forest package) name & version: @forestadmin/agent:1.12.0
  • Database type: MongoDB/mongoose
  • Recent changes made on your end if any: initial project setup

Kudos on the new agent release! Typescript … life is better <3

Hi @David_Roegiers

Are you using flattenMode: 'none'?
Many to many relationships need to create a virtual collection from the array of foreign keys.

I’ll add a ticket on our side to improve the documentation.

Can you switch to the following configuration?

createMongooseDataSource(connection, {
  flattenMode: 'manual',
  flattenOptions: { offices: { asModels: ['lawyers'] } }


Thanks! It was long overdue! :slight_smile:



Excellent, worked like a charm.

The out-of-the-box relationship intelligence is impressive and is saving us a lot of headache.


1 Like

You are more than welcome

Thank you for your kind words!