Location in mongoose, mongoDB

后端 未结 3 1447
再見小時候
再見小時候 2020-12-20 17:51

Whenever I try to store a location in my mongodb it doesn\'t show, so I guess I\'m doing something wrong. I can\'t find any documentation on how to store a location in mongo

3条回答
  •  自闭症患者
    2020-12-20 18:20

    I fixed it myself.

    I did this in my model:

    loc :  { type: {type:String}, coordinates: [Number]},
    

    Underneath I made it a 2dsphere index.

    eventSchema.index({loc: '2dsphere'});
    

    And to add data to it:

    loc: { type: "Point", coordinates: [ longitude, latitude ] },
    

提交回复
热议问题