I have Category
model:
Category:
...
articles: [{type:ObjectId, ref:'Article'}]
Article model contains ref to Account model
.
Article:
...
account: {type:ObjectId, ref:'Account'}
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' }
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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…