javascript - Convert MongoDB query result into JSONArray -
i have mongodb query via mongoose , result is: [ { "tablename": "name1" }, { "tablename": "name2" } ] but need jsonarray : { "tablename": [ "name1", "name2" ] } is there easy way convert? the aggregation framework can create desired result you. consider $group , $push accumulator operators follows: db.collection.aggregate([ { "$group": { "_id": null, "tablename": { "$push": "$tablename" } } }, { "$project": { "_id": 0, "tablename": 1 } } ]) sample output: /* 0 */ { "result" : [ { "tablename" : [ "name1", "name2" ] } ], "ok...