Now let's create our model to hold the location data:
Inside the app/models
folder, create a file called locations.js
and add the following code:
// Example model var mongoose = require('mongoose'), Schema = mongoose.Schema; varLocationSchema = new Schema({ title: String, coordinates: { type: [Number], index: '2dsphere' }, created: { type: Date, default: Date.now } }); mongoose.model('Location', LocationSchema);
It's important to note the data type of the coordinates property and the index of 2dsphere on the previous code.
Tip
You can read more about 2dsphere in the official documentation of MongoDB at: https://docs.mongodb.com/manual/core/2dsphere/.