Mongoose Schema secured field

前端 未结 4 1431
离开以前
离开以前 2020-12-17 20:02

Short and clear: is there any way to prevent setting a schema field but allowing to get the value?

I\'ve been around the Mongoose Documentation but can\'t find what

4条回答
  •  轮回少年
    2020-12-17 20:38

    Since mongoose 5.6 you can do: immutable: true

    var schema = new Schema({
      securedField: {
        type: String,
        default: 'Forever',
        immutable: true
      }
    });
    

提交回复
热议问题