Populate nested refObject in array
See original GitHub issueHi, I’m using 3.6.x version and here is my sample schema to reproduce :
var PersonSchema = new Schema({
name : String,
stories : [{ type: Schema.Types.ObjectId, ref: 'Story' }]
});
var StorySchema = new Schema({
creator : { type: Schema.Types.ObjectId, ref: 'Person' },
title : String,
});
I’m trying to populate the creator ref for each stories saved, I tried the both path :
Person.findById(user1._id).populate("stories stories.creator"}).exec(function(err, doc)
Person.findById(user1._id).populate("stories stories.$.creator"}).exec(function(err, doc)
but I got the: TypeError: Cannot call method ‘path’ of undefined
My tests is running here :https://runnable.com/UT9iTD2wDj1UACXx
Thank you
Issue Analytics
- State:
- Created 11 years ago
- Comments:6
Top Results From Across the Web
Populate nested array in mongoose - node.js - Stack Overflow
You can populate multiple nested documents like this. Project.find(query) .populate({ path: 'pages', populate: [{ path: 'components', model: 'Component' } ...
Read more >How to populate nested document in MongoDB.
To populate nested documents you have to use . populate() method like above. I'm very beginner at MongoDB. Thanks.
Read more >Mongoose: Problem populating nested array with aggregate
I've been trying to populate the user.profile.education array using aggregate . Particularly, the fields institution and major .
Read more >Mongoose v6.8.2: Query Population
Arrays of refs work the same way. Just call the populate method on the query and an array of documents will be returned...
Read more >Mongoose populate multiple levels | by Fred Wong - Medium
I have a Mongoose schema with an array lists of objects that consist of a reference to another collection and a nested… stackoverflow.com....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
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
Mongoose now supports deep populate. Example code: