in Mongoose, I have such a schema
var schema= mongoose.Schema({
         name:String,
         age:String
         likes: [{ type:String, price:String}]                       
});
As in the mongoose, the option in the Model.find(conditions, [fields], [options], [callback]) gives us a choice to select the fields we need. However in my schema, there is a array property 'likes', and in the query, I only want to select only one property type rather than all of them, how can I make this query ?
I actually found it out, just by
Model.findOne({ 'name': name }, 'name age likes.type', callback);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With