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 hidden or 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] | |
} | |
}); |
having a default to 0 0 is not a good idea
why ?
I believe that's because it is a valid location, hence when if there is a missing value it will default to resolve to 0,0 coordinates.
I believe that's because it is a valid location, hence when if there is a missing value it will default to resolve to 0,0 coordinates.
It's a non usable location. If you have Toronto POIS you could use Toronto Center instead, maybe.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
having a default to 0 0 is not a good idea