Dima Grossman
Dima Grossman

Reputation: 2830

Mongoose multiple nested select

I'm trying to put select on a large query using multiple nested selectors for example:

 .select('parent.0.item parent.0.item2 other item');

however the second item from parent array is never selected and only the first one returns. and suggestions ?

Upvotes: 0

Views: 235

Answers (2)

aitnasser
aitnasser

Reputation: 1246

in Mongoose version 4, you don't need to use select() as shown bellow

   yourModel.find({}, 'parent.item parent.item2 other item',
     function (err, docs) {
    });

Good luck

Upvotes: 0

Dima Grossman
Dima Grossman

Reputation: 2830

found that i had simply to remove the '.0,' and to write it like this:

.select('parent.item parent.item2 other item');

Upvotes: 1

Related Questions