【问题标题】:Validation Error Mongoose验证错误猫鼬
【发布时间】:2016-05-10 16:05:26
【问题描述】:

我一直在使用 Mongoose 向我的字段添加验证,但是当我测试它时,Mongoose 说我没有通过 _id 属性中的最大验证

    var userSchema = new mongoose.Schema{
      _id : {
        type : number,
        min:[6,"Your id is too short"],
        max:[10,"Your id is too large"]
        //This is the validation that sends
        // me when I put 2013090464 (10 digits)
      }
    }

【问题讨论】:

    标签: mongoose mongoose-schema


    【解决方案1】:

    _id 不能是type: number,它是一个 ObjectId。

    分配的类型是一个 ObjectId 以符合 MongoDB 的默认行为。

    http://mongoosejs.com/docs/guide.html#_id

    为什么不让 mongo 管理你的 _id 呢?

    【讨论】:

      猜你喜欢
      • 2020-07-18
      • 2016-09-23
      • 1970-01-01
      • 2013-01-02
      • 1970-01-01
      • 2020-03-26
      • 1970-01-01
      • 2016-02-14
      • 1970-01-01
      相关资源
      最近更新 更多