Mongoose Schema secured field

前端 未结 4 1439
离开以前
离开以前 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:22

    You can just return from set the same value as the default value, no need to reference the _this document:

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

提交回复
热议问题