Acording to the mongoDB documentation (link) if you want to store geospatial information in a document field, you have two options, an array or an embedded document, and the order should be always longitude, latitude.
If I want to use an embedded document, how can I ensure the field's order?
Or must the fields in the embedded document have a specific name?
MongoDB supports multiple GeoJSON types to store geospatial data. Throughout our examples, we'll mainly use the Point and Polygon types.
MongoDB supports the GeoJSON object types listed on this page. a field named coordinates that specifies the object's coordinates.
Choropleth. Choropleth charts use predefined shapes for geographical areas, e.g. the countries of the world, or the states of the United States. They are useful for comparing aggregated values across defined geographical areas.
with an embedded document, regardless of the name of the field in the embedded document, the first field should contain the longitude value and the second field should contain the latitude value. For example:
db.zips2.insert( { _id: 1, city: "b", loc: { x: -73.974, y: 40.764 } } ) db.zips2.insert( { _id: 2, city: "b", loc: { x: -73.981, y: 40.768 } } )
Here the x field would be the longitude; and the y field would be the latitude.
Regards
2D Geospatial Index, Store Location Data
"All documents must store location data in the same order. If you use latitude and longitude as your coordinate system, always store longitude first. MongoDB’s 2d spherical index operators only recognize [ longitude, latitude] ordering."
Here's a good post about Geospatial Queries in MongoDB in case you need it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With