在模型上按其引用模型的字段进行猫鼬嵌套查询

在模型上按其引用模型的字段进行猫鼬嵌套查询,第1张

模型上按其引用模型的字段进行猫鼬嵌套查询

您无法在单个查询中执行此 *** 作,因为MongoDB不支持联接。相反,您必须将其分为几个步骤:

// Get the _ids of people with the last name of Robertson.Person.find({lastname: 'Robertson'}, {_id: 1}, function(err, docs) {    // Map the docs into an array of just the _ids    var ids = docs.map(function(doc) { return doc._id; });    // Get the companies whose founders are in that set.    Company.find({founder: {$in: ids}}, function(err, docs) {        // docs contains your answer    });});


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5087694.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-16
下一篇2022-11-16

发表评论

登录后才能评论

评论列表(0条)

    保存