Can't make nested populate in new mongoose 3.6rc0
See original GitHub issueI have the following schemas:
var DocumentSchema = new Schema({
title : {type: String},
emails : [{type: ObjectId, ref: 'Emails'}]
});
var EmailSchema = new Schema({
title : {type: String},
tags : [{type: ObjectId, ref: 'Tags'}]
});
var TagSchema = new Schema({
title : {type: String}
});
I want to find a document with populated ‘emails’ and tags. When I try this:
Document.findById(ObjectId('...'))
populate('emails.tags')
.exec(function (err, document) {
});
I get the error:
Caught exception: TypeError: Cannot call method 'path' of undefined
Issue Analytics
- State:
- Created 11 years ago
- Comments:19
Top Results From Across the Web
Populate Nested Array In Mongoose - Node.Js - ADocLib
This tutorial gives you three ways to create and navigate to different screens using React cannot be used in embedded scripts unless such...
Read more >Mongoose でネストした populate の書き方 - Qiita
Mongoose の 3.6 から ネストした populate に対応したそうなので動作確認を試みたのです ... Can't make nested populate in new mongoose 3.6rc0.
Read more >mongooseを使ってmongodbでリレーションとjoinっぽいこと
mongoose の場合、Schema 定義の部分で ref を使うことでリレーションを表現 ... Can't make nested populate in new mongoose 3.6rc0 · Issue #1377 ...
Read more >Shared tabs - OneTab
javascript - Node.js - Creating Relationships with Mongoose - Stack Overflow ... Can't make nested populate in new mongoose 3.6rc0 · Issue #1377 ......
Read more >Mongoose find nested object in array
Mongoose helps you create nested schemas when you nest an object in another object . // This code is the same as above...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@yangsu you are correct. Though there is another way. Either specify the model that should be used for population in the options to
User.populate
or use thePhone
model directly:This seems clunky. We should be able to do better with this in a future release. If the documents being populated are mongoose documents (opposed to plain objects) we could possibly use it’s related schema to determine which Model to use. Won’t work for plain objects of course.
As the metadata for population is present in the ref property, shouldnt the libary be able to automatically guess the correct model for population?