Tuesday, 9 May 2017

Mongoose - Displaying sub-objects in projections

Using Node 6.10.0, MongoDB 2.2.26 and Mongoose 4.9.8 npms.

I have a schema like this:

{
    name: String,
    template: {
        name: String
    }
}

Calling...

model.find({}, { template: true }, (err, docs) => {
    console.log(docs);
});

Returns this...

{
    _id: 'ffffffffffffffffffffffff',
    name: 'foobar'
}

Why is the template field not shown automatically in the projection?



via Maxime Asselin

No comments:

Post a Comment