Understanding Geospatial indexes on MongoDB
Starting from version 2.4 of MongoDB, we have the Geospatial search feature using GeoJSON format.
Tip
You can find more information about GeoJSON at the official link: http://geojson.org/.
GeoJSON is an open source specification for formatting shapes in coordinates. It is widely used and very useful for making applications with geographical data. The format is pretty simple, and we used this format on the locations model, as you can see:
var LocationSchema = new Schema({
title: String,
coordinates: {
type: [Number],
index: '2dsphere'
},
created: {
type: Date,
default: Date.now
}
});
The highlighted code is the GeoJSON format to store coordinates.
Tip
You can read more about Geospatial query on MongoDB here: ...
Get Node.js 6.x Blueprints now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.