L
L
lssssssssssl2021-10-01 11:46:37
MongoDB
lssssssssssl, 2021-10-01 11:46:37

Models are connected unilaterally. How to tie them double-sided?

For example:
The user model stores the fields name, age, profileId[].
The Profile model stores progress, status. At the same time, one user can have many Profile.

I call it the "one-way" link in the question.

I want to add the userId field to all those already created in the Profile database, based on the data already available in the database about which User has which profileId.

As a result, I want to get a functional so that I can find out the owner of the profile when I get some kind of Profile.
In the existing one-way link, this can be done, as I understand it, only by getting all users and sorting through their profiles in search of the right one.

What query to the database should I write?

db.collection...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question