Location in mongoose, mongoDB

后端 未结 3 1448
再見小時候
再見小時候 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:28

    Looks like your comment is correct (maybe), but the syntax for the index schemetype

    here: http://mongoosejs.com/docs/api.html#schematype_SchemaType-index

    It only accepts Object, Boolean, String

    The correct syntax should be I think

    var eventSchema = new Schema({ 
            location: { type: [Number], index: { type: '2dsphere', sparse: true}}
    )
    

    based on the example in the docs.

提交回复
热议问题