Null set returned by mongodb aggregate Cursor in PHP -
mongodb aggregate query returning empty set .below query using in php script retrieve data mongodb .please let me know going wrong.
$result = $collection->aggregatecursor([[ '$match'=> [ 'date'=> [ '$gte'=>isodate("2015-06-01t00:00:00z"), '$lte'=>isodate("2015-06-03t00:00:00z")] ] ],[ '$group'=> [ '_id'=> '$date', 'count'=> [ '$sum'=>1 ] ] ]]);
if run same query in mongodb shell.it showing output expected.
db.mnumber.aggregate([{ $match: { date: { $gte:new isodate("2015-06-01t00:00:00z"), $lte:new isodate("2015-06-03t00:00:00z") } } },{ $group: { _id: "$date", 'count': { $sum:1 } } }]) { "_id" : isodate("2015-06-01t00:00:00z"), "count" : 10000 } { "_id" : isodate("2015-06-02t00:00:00z"), "count" : 10000 } { "_id" : isodate("2015-06-03t00:00:00z"), "count" : 10000 }
sample data in collection:
{ "_id" : objectid("55743941789a9abe7f4af3fd"), "msisdn" : "1234567890", "act_date" : isodate("2014-11-24t00:00:00z"), "date" : isodate("2015-06-07t00:00:00z"), "recharge_stats" : { "recharge_amt" : 0, "rechargetype" : "web" }, "voice_usage" : { "local_og_mou" : 20, "local_other_mobile_og_mou" : 0, "nld_og_mou" : 0, "nld_other_mobile_og_mou" : 10 }, "gprs_usage" : { "total_access_count" : 1, "total_datavolume_mb" : 42 }, "sms_usage" : { "freesms" : 3, "local_sms_count" : 0, "nat_sms_count" : 0, "inter_sms_count" : 0 }, "campaign_details" : { "camp_id" : "m01124", "message" : "hello .", "msg_id" : "9174051951412054925609431100", "cmp_activation_status" : "yes" } }
try generate mongodate()
object follows
$datefrom = new mongodate(strtotime("2015-06-01t00:00:00z")); $dateto = new mongodate(strtotime("2015-06-03t00:00:00z"));
which can use in aggregation pipeline instead of mongodb isodate objects in php query.
/* run command cursor */ $result = $collection->aggregatecursor( [ [ '$match' => [ 'date'=> [ '$gte' => $datefrom, '$lte' => $dateto ] ] ], [ '$group' => [ '_id' => '$date', 'count' => [ '$sum' => 1 ] ] ] ] );
Comments
Post a Comment