buunguyen / mongoose-deep-populate

Mongoose plugin to enable deep population of nested models ⛺
MIT License
469 stars 44 forks source link

Population not working in populated documents #48

Closed AlexBatorykLeliw closed 8 years ago

AlexBatorykLeliw commented 8 years ago

My schema is something along these lines:

var userSchema = new mongoose.Schema({
email: String,
     password: String,
         children: [
        {
            type: mongoose.Schema.Types.ObjectId,
            ref: 'users'
        }
    ]
});

Therefore I'm storing my ObjectIds inside the 'children' array, but these are recursive and users can go into other users.

The deepPopulation request is as such:

User.deepPopulate(req.user, 'children', function(err, users){
    if(err)
        return next(err);

    res.json(users);
});

Only the first instance is getting populated and all others are remaining with the array of ObjectId's. Can you please see if it is any issue of mine, or if the plugin is not working?

Thank you