|
I think the requested feature is a duplicate of SERVER-23310, in the sense that once SERVER-23310 is implemented it would be trivial to achieve the functionality described in this ticket by using the $arrayToObject operator.
darkbasic, please take a look at Asya's blog for examples on using the aggregation pipeline, I think you should be able to accomplish what you need even if your pipeline is a bit more elaborate.
Playing a bit with the example in stackoverflow I came up with this:
> db.test.aggregate([
|
{$unwind : "$tags" },
|
|
{$group : {
|
_id : { "d" : "$day", "t" : "$tags" },
|
count : {"$sum" : 1}
|
}},
|
|
{$group : {
|
_id : "$_id.d",
|
tags : {$push : { t : "$_id.t", c : "$count"}}}
|
},
|
|
]);
|
|
{ "_id" : "2010/01/12", "tags" : [ { "t" : "sledding", "c" : 2 }, { "t" : "winter", "c" : 10 }, { "t" : "nosql", "c" : 4 } ] }
|
{ "_id" : "2010/01/13", "tags" : [ { "t" : "soda", "c" : 5 }, { "t" : "php", "c" : 2 } ] }
|
{ "_id" : "2010/01/14", "tags" : [ { "t" : "python", "c" : 6 }, { "t" : "nosql", "c" : 15 }, { "t" : "winter", "c" : 4 } ] }
|
Hope that helps.
|
|
Hi, sorry if I'm not been clear. Mine is not a question: it's a feature request. Currently the aggregation framework allows to craft an array using the $push operator, the feature I'm requesting for is the ability to craft objects instead of arrays. I want the result to be a document with subdocuments. I need something like "$addToSubdocument" : {"subdocument_name" : {"$key" : "$value"}} to be able to push my tags and their values inside my "tags" subdocument. My use case is well explained in the stackoverflow question, that's whay I linked it.
|