0

I want to change the order of result and the format as well. The format is just like Findone(); however, I want to use aggregate function in my code. Thank you!!

My current code is like this.

db.zips.aggregate(
{$project:{ city: 1, loc: 1, pop: 1, state: 1, _id: 1}},
{$sort:{ state:1, city:1}}
)

Current Result Current Result

Goal Goal

Community
  • 1
  • 1
  • What are the changes you need to have on the goal over current result. To have only one document ? – Lakmal Vithanage Apr 24 '16 at 07:17
  • Please correct your Code Tag and explain why you want to sort. Also i can't identify a formating difference between the both BSON objects (eycept the space) – Clijsters Apr 24 '16 at 07:19

2 Answers2

0

BSON is a representation of JSON.

There is no need for changing the sort of the documents properties. So no, there is no aggregate function to accomplish this.

You have to go on your own. While a simple loop would have the same problem, for this small document, you can access the properties separately.

Also have a look at this question and its comments (related questions).

Community
  • 1
  • 1
Clijsters
  • 4,031
  • 1
  • 27
  • 37
0

If your purpose is soley the Aggregation, you don't need to change the order of the document, you can just use the aggregate function as needed

Amit
  • 145
  • 3
  • 11