node.js - Mongoose $ project -


using mongoose 4.0.x, need execute following (working) mongodb query:

db.bookings.find(   {     user: objectid("10"), // replaced real id     'flights.busy.from': {$gte: isodate("2015-04-01t00:00:00z")},     'flights.busy.to': {$lte: isodate("2015-04-01t23:59:00z")}   },   {     'flights.$': 1 // don't know replicate   } ).pretty() 

the mongoose find operator not accept projection operator, mongodb find 1 does.

how can replicate above query in mongoose? filtering array once query returned solution avoid.

you want @ docs model.find, not query.find. second parameter can used field selection:

mymodel.find(   {     user: objectid("10"), // replaced real id     'flights.busy.from': {$gte: isodate("2015-04-01t00:00:00z")},     'flights.busy.to': {$lte: isodate("2015-04-01t23:59:00z")}   },   'flights.$' ).exec(function(err, docs) {...}); 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -