Mongoose Schema secured field

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

    An alternative if you want to set a default value that can never be changed:

    var schema = new Schema({
      securedField: {
        type: String,
        default: 'Forever',
        set: function (val) { return this.securedField; }
    });
    

提交回复
热议问题