Search code examples
node.jsmongodbmongoosegeojson

How do i create a schema for a geojson data in mongoose?


I am working with mapbox api and I want to maintain a geojson data on my server itself so that i can fetch the data from this file to put pins on the map. if any one can tell me about the correct schema that has to be used for a geojson data then it would be really a great help for me.


Solution

  • Here is the simple schema for one Point. and remember in mongo DB you have save [lon, lat]. in contrast to common pratice where latitude is mentioned first.

     {
                type       : {type: String, default: 'Point'},
                coordinates: {type: [Number]}
            }