1

i have some data where ISO date is getting stored as string and i am running $substr to get the count Match with substring in mongodb aggregation but count mismatch is coming day by day. couldnot able to figure out why. database is in mlab.com which stores UTC and my code running on IST.. is this leading to mismatch? planning to use $regex but not getting how to

data is like

{"_id": {"$oid": "580af4ce1b407e114sdvsdbf"},
    "isActive": "1",
    "createdAt": "2016-10-22T05:10:38.632Z",
},
{"_id": {"$oid": "580af4ce1b407safasfe114bf"},
    "isActive": "1",
    "createdAt": "2016-10-22T05:10:38.632Z",
},
{"_id": {"$oid": "580af4ce1b407f495sagfdgaed"},
    "isActive": "1",
    "createdAt": "2016-10-21T05:10:38.632Z",
},
{"_id": {"$oid": "580af4ce1b407f4956436sdg"},
    "isActive": "1",
    "createdAt": "2016-10-20T05:30:38.632Z",
},
{"_id": {"$oid": "580af4ce1b407f495safasgvd"},
    "isActive": "1",
    "createdAt": "2016-10-10T05:05:38.632Z",
},
{"_id": {"$oid": "580af4ce1b407f495325ds"},
    "isActive": "1",
    "createdAt": "2016-10-10T08:10:38.632Z",
}

and my query is

var data = db.userprofiles.aggregate(
    [   
        {   $match:  { isActive: "1"} },
        {   $project : { day : {$substr: ["$createdAt", 0, 10] } }},        
        {   $group   : { _id : "$day",  number : { $sum : 1 }}},
        {   $sort    : { _id : 1 }}        
    ]
) 

could someone help me to resolve this count mismatch problem?

Community
  • 1
  • 1
Priyanka D L
  • 171
  • 1
  • 8
  • 1
    what is the count mismatch you are getting? – hyades Oct 22 '16 at 07:57
  • lets say for `2016-10-22` date count is 3 today, tomorrow count is coming as 2 for `2016-10-22`.. i have 6Lakhs records, so i couldnot check which date record is correct.. i could say as days goes on it is decreasing .. and $regex count is not matching $substr count.. why so? – Priyanka D L Oct 24 '16 at 13:23

0 Answers0