0

i have already a collection of documents like this way:

{"name": "apple", "cnt": 10}
{"name": "orange", "cnt": 15}
{"name": "banana", "cnt": 12}
{"name": "grapefruit", "cnt": 2}

i want to transform them into an array of documents and that should look like this:

[
    {"name": "apple", "cnt": 10},
    {"name": "orange", "cnt": 15},
    {"name": "banana", "cnt": 12},
    {"name": "grapefruit", "cnt": 2} 
]

Any suggestions on how can i do it? Thank in you in advance

EDIT

Mongo group and push: pushing all fields

i already tried the push editor

{ $group : {fish: { $push : "$$ROOT" }}} 

but in vain

Community
  • 1
  • 1
user3623460
  • 103
  • 1
  • 1
  • 8
  • Possible duplicate of [Mongo group and push: pushing all fields](https://stackoverflow.com/questions/22150205/mongo-group-and-push-pushing-all-fields) – s7vr Jun 14 '17 at 20:32
  • @Veeram i already tried ,you can see the edit section but vainly – user3623460 Jun 15 '17 at 00:05
  • [Group](https://docs.mongodb.com/manual/reference/operator/aggregation/group/) requires both id and accumulators. Use [group on null](https://docs.mongodb.com/manual/reference/operator/aggregation/group/#group-by-null) to aggregate over entire collection. Something like `db.collectioname.aggregate({ $group : { _id : null, docs: { $push : "$$ROOT" } }})` should work as expected. – s7vr Jun 15 '17 at 00:09

0 Answers0