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});
1const polygonSchema = new mongoose.Schema({
2 type: {
3 type: String,
4 enum: ['Polygon'],
5 required: true
6 },
7 coordinates: {
8 type: [[[Number]]], // Array of arrays of arrays of numbers
9 required: true
10 }
11});
12
13const citySchema = new mongoose.Schema({
14 name: String,
15 location: polygonSchema
16});