相关疑难解决方法(0)

如何在Mongoose模式中设置数组大小的限制

您是否善意告诉我在创建Mongoose模式时是否有任何方法可以限制数组大小.例如

 var peopleSchema = new Schema({
    name: {
        type: String,
        required: true,
        default: true
    },
   /* here I want to have limit: no more than 10 friends.
    Is it possible to define in schema?*/
    friends: [{
        type: Schema.Types.ObjectId,
        ref: 'peopleModel'
    }]
})
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js

28
推荐指数
3
解决办法
2万
查看次数

标签 统计

mongodb ×1

mongoose ×1

node.js ×1