Reference embedded in object does not work

I’m trying to display “groups” where each element is an object containing a reference to “group” document.


Expected behavior

Each group has an “_id” field which links to the actual “group” document, with “pastSessionsCount” and “attendedSessionsCount”.

Actual behavior

“_id” field is empty without error messages in the console.

Failure Logs

No failure logs are being displayed.


  • Express Version: “~4.16.3”
  • Database Type: “MongoDB”
  • Project Name: “BTAttendanceSystem”

Hello @linsze and welcome to the Forest Admin community,

Given your code snippet, I think you already checked our documentation?
This might also help

Could you share your model files for groups and the one using them?

I think you already checked our documentation?
Yes I’ve already done that. It doesn’t seem to work the way I expect to be probably because it’s not a direct referencing.

Could you share your model files for groups and the one using them?
The model file for “groups”:

The model file for “students”:

Would you mind trying to rename the second _id to something like groups_id? It might lead to a confusion with primary key reserved field name.

I changed the first “_id” to “group” and the columns are no longer empty. However, it is still not showing the link to the referenced group document.

Could you please retry with group_id and if not working groups_id? Naming could matter here when your models are analysed.

Tried both and it’s still not working.

Hello @linzse,

Embedded documents with references in mongo is not currently supported by Forest Admin. It will be addressed to our product team.
Classic HasMany (array of Object Id) relationships are supported.
For dealing with relationships, you will need to modify your schema for adding a related table dedicated to a subscribed_group model by user with its pastSessionCount and attendedSessionCount fields.

You can also use smart relationships for this kind of issue.

Hi, when I tried with smart relationships, the links to the referenced “group” were shown but pastSessionsCount and attendedSessionsCount disappeared. Do you have any suggestions to overcome this? I tried modifying the local models of a “group” to include those fields but it didn’t work since those fields do not exist in the actual “group” document in the database.

Hi @linsze,

How did you create your smart relationships?
Maybe you can looks at Managing nested documents in Mongoose.

Let me know if it helps,