How does one represent MongoDB GeoJSON fields in a Mongoose Schema?

前端 未结 5 1593
猫巷女王i
猫巷女王i 2020-12-07 11:44

MongoDB 2.4 allows the use of GeoJSON objects and a slew of neat functions and indexes that I\'d like to use.

It expects GeoJSON objects to be stored in the format l

5条回答
  •  一个人的身影
    2020-12-07 12:32

    For reference, GeoJSON is officially supported in Mongoose 3.6

    See the release notes here.

    Example (from the docs):

    new Schema({ loc: { type: [Number], index: '2dsphere'}})
    

    ... then ...

    var geojsonPoly = { type: 'Polygon', coordinates: [[[-5,-5], ['-5',5], [5,5], [5,-5],[-5,'-5']]] }
    
    Model.find({ loc: { $within: { $geometry: geojsonPoly }}})
    // or
    Model.where('loc').within.geometry(geojsonPoly)
    

提交回复
热议问题