【发布时间】:2017-02-24 21:55:30
【问题描述】:
我有下面的架构,它允许我为现有应用创建一个徽章为“1234567”的用户。我预计会收到 maxlength 验证的验证错误 b/c。
我的架构有问题吗?
module.exports = function(db) {
var mongoose = require('mongoose');
var appSchema = mongoose.Schema({
name: {
type: String,
required: true,
unique: true,
},
settings: mongoose.Schema.Types.Mixed,
user: [{
badge: {
type: String,
minlength: 5,
maxlength: 5
}
}]
});
// Export the schema for the app to use
return db.model('apps', appSchema);
}
我正在尝试使用
apps.findByIdAndUpdate(req.params.id, {$push: {user: req.body.user}}, {runValidators: true},callback());
向应用文档中的数组添加新的用户记录。
【问题讨论】:
标签: node.js mongodb mongoose mongoose-schema