I have a mongoose schema and model defined as follows:
var mongoose = require(\'mongoose\')
, Schema = new mongoose.Schema({
email: {
index:
The correct way to create a schema with geolocation and run geospartial queries was
var UserSchema = new Schema({
location: {
type: {
type: String,
enum: ["Point"], // 'location.type' must be 'Point'
},
coordinates: {
type: [Number]
}
}
});
UserSchema.index({location: '2dsphere'});
Be careful this is important to do, the index 2dsphere in the location.coordinates, if you want to run geospartial queries!