0

I have a MongoDB with Mongoose ODM. I downloaded the backup of the database and wanted to pull the query from the one of the collections and store it in the separate collection.

Here is the example of the data:

{
 id: 01;
 name: a;
 coordinates:{
  x;
  y;
 };
};
{
 id: 02;
 name: b;
 coordinates:{
  x;
  y;
 };
}

But once I make a query to save it in new collection some of the documents have the coordinates changed vise-versa. Is there any way to prevent it and query results in the specific order?

  • You mean the `x` and `y` of the `coordinates` object change order? That's to be expected, as object properties are [unordered](http://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order). – robertklep Oct 26 '16 at 21:01
  • I see. I know they are usually in the right order when I do not aggregate them myself. Would it make sense to $unwind and use $first for x and $last for y calling them Lat and Lon in the $group? – Ivan Veligore Oct 26 '16 at 22:36
  • `$unwind` is for arrays, isn't it? `coordinates` isn't an array, it's an object. Why does the order in which properties appear in an object matter, though? – robertklep Oct 27 '16 at 06:30

0 Answers0