mongodb - Get all records with specified properties between a certain date range -
i passing in 2 dates formatted mm-dd-yyyy
date range. need query records within range , include specified fields. i've had no luck.
part of record in mongo:
{ "_id": "some id", "date": { "$date": "2015-06-26t13:02:12.121z" },
query:
var start = '09-07-2015' var end = '09-14-2015'
if do:
var query = order.find({ date : { $lt : end, $gt : start } });
i full document within week ranges expected. however, want specify fields return rather full document. i've tried using grouping , project specify fields:
var query = order.aggregate( { $match : { date: { $gte: start, $lt: end } }, $group: { cust_id: '$request.headers.customer_id', wholesaler_id: '$request.headers.wholesalerid' } } );
likewise: i've tried using project results want. thought maybe won't match on date string 09-07-2015
, included iso date directly. still no luck... query comes undefined or empty:
var query = order.aggregate( { $project: { date: 'date', cust_id: '$request.headers.custid', wholesaler_id: '$request.headers.wholesalerid' } }, { $match : { date: { $gte: "2014-12-09t21:02:56.872z", $lt: "2015-12-09t21:02:56.872z" } } } );
var query = order.find({ date : { $lt : end, $gt : start }}, {cust_id:1, wholeseller_id:1} );
this work.
i tested using robomongo
db.getcollection('offerdb').find({time_posted:{$gt: '2015-10-21t21:40:04+05:30', $lte:'2015-12-14t05:53:14+05:30'}},{_id:1, merchant_id:1})
works charm me.
Comments
Post a Comment