Does applying a 2dsphere index on a mongoose schema force the location field to be required?

后端 未结 4 602
长发绾君心
长发绾君心 2020-12-15 23:17

I have a mongoose schema and model defined as follows:

var mongoose = require(\'mongoose\')
  , Schema = new mongoose.Schema({
      email: {
        index:          


        
4条回答
  •  伪装坚强ぢ
    2020-12-15 23:47

    For mongoose 3.8.12, you set the default value:

    var UserSchema = new Schema({
      location: {
        type: {
          type: String,
          enum: ['Point'],
          default: 'Point',
        },
        coordinates: {
          type: [Number],
          default: [0, 0],
        }
      }
    });
    
    UserSchema.index({location: '2dsphere'});
    

提交回复
热议问题