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?