Error Creating Virtual Relationship

Feature(s) impacted

Smart Relationships (Has Many) with MongoDB

Observed behavior

I have a tag collection and a client collection. A client has many tags. On each tag is a client which references client._id. I do not want a tags array on my client Mongo collection (for backwards compatibility).

I have added a smart relationship to my forest/client.js however I get a Mongo related error when I try to view a client

StrictPopulateError: Cannot populate path `tags` because it is not in your schema. Set the `strictPopulate` option to false to override.

Smart relationship definition:

fields: [
    {
      field: 'tags',
      type: ['String'],
      reference: 'tag._id',
    },
  ],

I’ve tried making this as similar to the example described here as possible, however the error persists.

Expected behavior

Ideally I’d like to be able to interact with tags from the client page as if a tags array existed on my client (but just by using the inverse relationship). I.e. I’d like to be able to see and create tags that have the client auto populated with the current client._id

Failure Logs

[forest] 🌳🌳🌳  Unexpected error: Cannot populate path `tags` because it is not in your schema. Set the `strictPopulate` option to false to override.
{
  "path": "tags",
  "stack": "StrictPopulateError: Cannot populate path `tags` because it is not in your schema. Set the `strictPopulate` option to false to override.\n    at getModelsMapForPopulate (/Users/<<redacted>>/Projects/<<redacted>>/node_modules/mongoose/lib/helpers/populate/getModelsMapForPopulate.js:49:12)\n    at populate (/Users/<<redacted>>/Projects/<<redacted>>/node_modules/mongoose/lib/model.js:4325:21)\n    at _populate (/Users/<<redacted>>/Projects/<<redacted>>/node_modules/mongoose/lib/model.js:4285:5)\n    at /Users/<<redacted>>/Projects/<<redacted>>/node_modules/mongoose/lib/model.js:4257:5\n    at new Promise (<anonymous>)\n    at Function.populate (/Users/<<redacted>>/Projects/<<redacted>>/node_modules/mongoose/lib/model.js:4256:10)\n    at Query._completeOne (/Users/<<redacted>>/Projects/<<redacted>>/node_modules/mongoose/lib/query.js:2484:18)\n    at /Users/<<redacted>>/Projects/<<redacted>>/node_modules/mongoose/lib/query.js:2527:10\n    at new Promise (<anonymous>)\n    at model.Query._findOne (/Users/<<redacted>>/Projects/<<redacted>>/node_modules/mongoose/lib/query.js:2526:10)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async model.Query.exec (/Users/<<redacted>>/Projects/<<redacted>>/node_modules/mongoose/lib/query.js:4419:11)"
}

Context

  • Project name: NA
  • Team name: NA
  • Environment name: NA
  • Agent (forest package) name & version: "forest-express-mongoose": "^9.3.6"
  • Database type: MongoDB
  • Recent changes made on your end if any: NA

Hi @Jemit,

I will try to reproduce on my side. I’ll let you know as soon as I have news

Hey @Jemit,
I do reproduce. It seems we don’t support the latest version of mongoose.
I will create a bug ticket. We will let you know as soon as it is fixed :wink:

Hello @Jemit
The latest release of forest-express-mongoose v9.3.9 supports latest versions of mongoose.

Best regards,

Thanks both, this is indeed working now

1 Like