I've been trying to use the aggregate function to group date fields by year:
db.identities.aggregate([
{
$group : {
_id : { year : {$year : "$birth_date"}},
total : {$sum : 1}
}
}
])
Some of my dates however fall before 1970 and being a Windows user I get a nasty error about gmtime:
{
"errmsg" : "exception: gmtime failed - your system doesn't support dates before 1970",
"code" : 16422,
"ok" : 0
}
I know the obvious answer now is for me to get a virtual machine running or something but I was just curious if there were any work-arounds for windows (Windows 7 in my case). Failing that how much of a performance hit would storing the date as a nested object be i.e:
birth_date : {
year : 1980,
month : 12,
day : 9
}
I'm not too sure how hectic that would be with indexes etc.
Any advice appreciated!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…