Mongodb relations

System Information
  • Strapi Version:
  • Operating System:
  • Database:
  • Node Version:
  • NPM Version:
  • Yarn Version:

Dear Strapi team,
I’m a super junior dev. and working on a blog project.
I’m going crazy trying to define relationships on Strapi and retrieve them in Mongodb.
Here’s my issue :

  • I have 3 Content Types : posts, authors and categories. Each post can have multiple authors and categories (many to many relation). When I set the relation on Strapi everything is fine : I can retrieve for each post the author and the categories.

However, when I check the database (using Mongo Compass) there is no relation on the Posts collection. I can find the relation on the Author collection (I see the related posts) and the Category collection (again I see the related posts).

Is there something I’m misunderstanding? Do I need to create special controllers?
This issue is driving me crazy for several days…

Thanks in advance!

Best

Strapi doesn’t follow the standards of MongoDb when it comes to a structure like this, we more or less treat MongoDB as a relational database, thus certain relations will have a dominate tag assigned (you can find this in the model settings file under ./api/*/models/*.settings.json.

Depending on the type of relation the value of those relations may be stored on one side or a middle collection/table.

Can you give the settings files for your content-types and maybe some test data so I can reproduce locally?

Thanks DMehaffy,
I’ve created a brand new Strapi project, just to check if something was wrong in the other one. Same issue here, the data is only stored in one collection (i.e author of the article stored with an ObjectId in the Article Collection, but an empty array in the Author Collection, for the articles).

I’ve checked the Strapi doc, and on this new project my dominant collection is the Author Collection (I know how to change this to make the Article Collection dominant). Here’s some print screens of my settings.

If Strapi doesn’t follow MongoDb standards and only uses a dominant to store the relational data, the only way to access the relational data is to join the infos in the backend, with some variables or stuff like this ?

Thanks in advance!