本文介绍了猫鼬:人口众多(人口众多)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有Category
模型:
Category:
...
articles: [{type:ObjectId, ref:'Article'}]
商品模型包含对Account model
的引用.
Article model contains ref to Account model
.
Article:
...
account: {type:ObjectId, ref:'Account'}
因此,使用填充的articles
类别模型将是:
So, with populated articles
Category model will be:
{ //category
articles: //this field is populated
[ { account: 52386c14fbb3e9ef28000001, // I want this field to be populated
date: Fri Sep 20 2013 00:00:00 GMT+0400 (MSK),
title: 'Article 1' } ],
title: 'Category 1' }
问题是:如何填充已填充字段([articles])的子字段(帐户)?这是我现在的操作方式:
The questions is: how to populate subfield (account) of a populated field ([articles])? Here is how I do it now:
globals.models.Category
.find
issue : req.params.id
null
sort:
order: 1
.populate("articles") # this populates only article field, article.account is not populated
.exec (err, categories) ->
console.log categories
我知道在这里进行了讨论:猫鼬:填充一个填充字段,但没有找到了真正的解决方案
I know it was discussed here: Mongoose: Populate a populated field but no real solution was found
推荐答案
猫鼬现在有了用于深度关联的新方法Model.populate
:
Mongoose has now a new method Model.populate
for deep associations:
https://github.com/Automattic/mongoose/issues/1377 #issuecomment-15911192
这篇关于猫鼬:人口众多(人口众多)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!