I work a lot with MongoDb Geospatial indexing, and now I am in the process of replacing the old NoRM framework with the official 10gen C Sharp driver. The problem I am having is that for the existing data that was handled by NoRM, coordinates were in the opposite order [y,x] and it seems like the official driver doesn’t like it.
So I for the existing data I have this structure:
{
"Coordinates" [:
{
"Longitude" : -85.68216,
"Latitude" : 38.221452
},
//.. more coordinates
]
}
So my question is, how can I modify the order of all the elements within the array so it they look like:
{
"Coordinates" [:
{
"Latitude" : 38.221452,
"Longitude" : -85.68216
},
//.. more coordinates
]
}
Thanks!
If you want to reverse the order, you’ll need to go through the entire collection and rewrite each document in the correct format. Here’s some JavaScript code to do that: feel free to season to taste.