These are chat archives for Automattic/mongoose

17th
Jul 2016
Paul "Joey" Clark
@joeytwiddle
Jul 17 2016 04:24
@DylanPiercey Does this article do what you need? http://frontendcollisionblog.com/mongodb/2016/01/24/mongoose-populate.html (I remember the built-in behaviour used to be limited to inner schemas in some way.)
If not, you may need to use a plugin: https://www.npmjs.com/package/mongoose-deep-populate
Dylan Piercey
@DylanPiercey
Jul 17 2016 23:21

@joeytwiddle I was more looking for a way to achieve what the article achieves but using only a string as the populate option.

I ended up writing a little parser that works like this, thanks for the link!

parsePopulate(Model, 'user[name posts]:posts[title]'); //-> [{
    path: 'user',
    model: ...,
    select: 'name posts',
    populate: {
        path: 'posts',
        select: 'title',
        model: ...
    }
}]