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
Post a Comment