Just a simple query, for example with a double ref in the model.
Schema / Model
JavaScript
x
17
17
1
var OrderSchema = new Schema({
2
3
user: {
4
type : Schema.Types.ObjectId,
5
ref : 'User',
6
required: true
7
},
8
9
meal: {
10
type : Schema.Types.ObjectId,
11
ref : 'Meal',
12
required: true
13
},
14
});
15
16
var OrderModel = db.model('Order', OrderSchema);
17
Query
JavaScript
1
7
1
OrderModel.find()
2
.populate('user') // works
3
.populate('meal') // dont works
4
.exec(function (err, results) {
5
// callback
6
});
7
I already tried something like
JavaScript
1
3
1
.populate('user meal')
2
.populate(['user', 'meal'])
3
In fact only one of the populates works.
So, how do is get two populates working ?
Advertisement
Answer
You’re already using the correct syntax of:
JavaScript
1
7
1
OrderModel.find()
2
.populate('user')
3
.populate('meal')
4
.exec(function (err, results) {
5
// callback
6
});
7
Perhaps the meal
ObjectId from the order isn’t in the Meals
collection?