Created
December 6, 2017 15:18
-
-
Save eastenluis/d4564daf7312c657748fc6a3dc5fceec to your computer and use it in GitHub Desktop.
Mongoose GeoJSON schema example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mapItemSchema = new mongoose.Schema({ | |
name: String, | |
location: { | |
// It's important to define type within type field, because | |
// mongoose use "type" to identify field's object type. | |
type: {type: String, default: 'Point'}, | |
// Default value is needed. Mongoose pass an empty array to | |
// array type by default, but it will fail MongoDB's pre-save | |
// validation. | |
coordinates: {type: [Number], default: [0, 0]} | |
} | |
}); | |
const MapItem = mongoose.model('MapItem', mapItemSchema); | |
MapItem.create({ | |
name: 'Toronto', | |
location: { | |
type: 'Point', | |
// Place longitude first, then latitude | |
coordinate: [-79.3968307, 43.6656976] | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's a non usable location. If you have Toronto POIS you could use Toronto Center instead, maybe.