Reputation: 5291
I have a mongodb query that results data in the following format
[{"_id":1471424941,"value":[1444,0]},{"_id":1471424941,"value":[1444,0]}]
and I would like to convert the result into
[[1471424941, 1444,0],[1471424941, 1444,0]]
Will this be possible using aggregate method ? I want to avoid using Javascript for the conversion and want to do it using mongodb if possible.
Can MongoDb produce an aggreation that will remote the value of the keys from the result
Upvotes: 0
Views: 758
Reputation: 103455
Run the following aggregation pipeline which uses the $concatArrays
operator to concatenate arrays and get the desired result as a key:
db.collection.aggregate([
{
"$project": {
"items": { "$concatArrays": [ "$value", ["$_id"] ] }
}
},
{
"$group": {
"_id": null,
"items": { "$push": "$items" }
}
}
])
Upvotes: 1