ruby on rails - An Hash with aggregation framework -
i using rails mongoid, syntax language.
my mongodb objects these:
{ "_id" : "asset01_*00001", "total" : 124 ...}, { "_id" : "asset01_*00002", "total" : 99 ...}, {...}
the project operator is:
{"project" => {"_id" => 1, "pair" => {"$add" => {"$_id" => "$total"}} }}
and group operator is:
{"$group" => { "invoice" => { "$push" => "$pair"} }}
but throws following error:
the $add operator not accept object operand
i know meaning of error, have alternative problem?
the result is:
{ "_id" => 1, "pair" => {"asset01_*00001" => 124, "asset01_*00002" => 99 ... }
a hash of {asset_id => number}
thanks
you want transform field values keys in results.
unfortunately that's not possible, there a feature request it can vote in mongodb jira system.
Comments
Post a Comment