Answer the question
In order to leave comments, you need to log in
What is the best way to organize the storage of a list of something, for example, ids?
In this case, we are talking only about NODEJS and MONGODB.
Take the example of the User table and the friends field and, for example, add 1,2,3,4, etc., id friends, separated by commas, and then, to display, say, data for each of their list, send requests to the User table of a specific user, the only thing that came to mind, are there better ways to organize?
Answer the question
In order to leave comments, you need to log in
In this context, the most correct option. User with a friends field, which is of type list. But it is not necessary to send a separate request for each user. You can manage with 2 queries (select the current user, and then select all users with ids in the user.friends list). Well, or even one through aggregation.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question