Answer the question
In order to leave comments, you need to log in
How does populate work in mongoose?
I create a simple chat.
There are three models: Users, Dialogs, Messages.
By analogy with populate in Waterline, I thought to build the following:
The database stores dialogs of the following form:
creator: '1';
members: ['1', '2']
The numbers are the user IDs from Users.
When searching through the database of dialogs, I wanted to immediately load the necessary data for users by these IDs, so I made the dialog model as indicated in the documentation:
var DialogSchema = new Schema({
creator: String,
members: [{type: Schema.Types.ObjectId, ref: 'User'}]
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question