多个群体 - mongoosejs [英] Multiple populates - mongoosejs
本文介绍了多个群体 - mongoosejs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是一个简单的查询,例如在模型中使用双引用.
Just a simple query, for example with a double ref in the model.
架构/模型
var OrderSchema = new Schema({
user: {
type : Schema.Types.ObjectId,
ref : 'User',
required: true
},
meal: {
type : Schema.Types.ObjectId,
ref : 'Meal',
required: true
},
});
var OrderModel = db.model('Order', OrderSchema);
查询
OrderModel.find()
.populate('user') // works
.populate('meal') // dont works
.exec(function (err, results) {
// callback
});
我已经尝试过类似的东西
I already tried something like
.populate('user meal')
.populate(['user', 'meal'])
实际上只有其中一个有效.
In fact only one of the populates works.
那么,如何让两个人工作?
So, how do is get two populates working ?
推荐答案
您已经在使用正确的语法:
You're already using the correct syntax of:
OrderModel.find()
.populate('user')
.populate('meal')
.exec(function (err, results) {
// callback
});
也许订单中的 meal
ObjectId 不在 Meals
集合中?
Perhaps the meal
ObjectId from the order isn't in the Meals
collection?
这篇关于多个群体 - mongoosejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文