I try to create a 2dsphere index in my collection, when i create a user that i should has a 2dsphere index.
I take a reference from this answer Create & Find GeoLocation in mongoose
I use the code is this in my case:
DriverSchema.index({ "geometry": "2dsphere"});
But when i create a user, i don't see any 2dsphere index.
I don't know which step was wrong, wish some one can tell me.
Here is my schema code:
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const PointSchema = new Schema({
type: { type: String, default: 'Point'},
coordinates: { type: [Number], index: '2dsphere'}
});
const DriverSchema = new Schema({
email: {
type: String,
required: true
},
driving: {
type: Boolean,
default: false
},
geometry: PointSchema
});
DriverSchema.index({ "geometry": "2dsphere"});
const Driver = mongoose.model('driver', DriverSchema);
module.exports = Driver;
Thanks in advance.