1const citySchema = new mongoose.Schema({
2 name: String,
3 location: {
4 type: {
5 type: String, // Don't do `{ location: { type: String } }`
6 enum: ['Point'], // 'location.type' must be 'Point'
7 required: true
8 },
9 coordinates: {
10 type: [Number],
11 required: true
12 }
13 }
14});
1var locQuery = (coords, distance) => {
2 return { loc: { $near: { $geometry: { type: "Point", coordinates: coords }, $maxDistance: parseInt(distance)}}}
3}