db['cfs.medias.filerecord'].aggregate(
[
{
$project:
{
year: { $year: "$uploadedAt" },
month: { $month: "$uploadedAt" },
day: { $dayOfMonth: "$uploadedAt" },
hour: { $hour: "$uploadedAt" },
minutes: { $minute: "$uploadedAt" },
seconds: { $second: "$uploadedAt" },
milliseconds: { $millisecond: "$uploadedAt" },
dayOfYear: { $dayOfYear: "$uploadedAt" },
dayOfWeek: { $dayOfWeek: "$uploadedAt" },
week: { $week: "$uploadedAt" }
}
},
{ "$group" :
{ "_id" : {
"year" : "$year",
"month" : "$month",
"day" : "$day"
},
"medias": {
"$push": {id:"$_id"}
}
}
}
]
);> db.test.drop()
> db.test.insert({ "_id" : 0, "a" : 1, "b" : 2, "c" : 3 })
> db.test.insert({ "_id" : 1, "a" : 1, "b" : 4, "c" : 5 })
> db.test.aggregate([
{ "$group" : { "_id" : "$a", "bs" : { "$push" : "$b" }, "cs" : { "$push" : "$c" } } }
])
{ "_id" : 1, "bs" : [ 2, 4 ], "cs" : [ 3, 5 ] }
What are you trying to do with this pipeline, exactly? It's often a sort of anti-pattern to be trying to write a pipeline that wants to store all the documents of a group using $$ROOT, or, somewhat similarly, to want an output from a pipeline that looks like the documents from the original collection, though occasionally it's reasonable.
-Will