0

I have millions of documents with the following schema:

{
   _id: '3fbwehgzgfwehgrqwegrqwer',
   someData: [0,1],
   moreData: {
       key: true
   } 
},

{
   _id: '24nj5h219ebwjfqwverqwer',
   someData: [2,3],
   moreData: {
       key: true
   } 
},

I need the someData array combined in a result array like:

{
    result: [
       [0,1],
       [2,3] 
    ]
}

1 Answer 1

5

Using aggregation pipeline, you can $group by _id: null, than $push all $someData in result field:

db.collection.aggregate([
    {"$group":{_id: null, result: {$push: "$someData"}}} 
]).pretty()

Result:

{ "_id" : null, "result" : [ [ 0, 1 ], [ 2, 3 ] ] }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.