Mongo3.2有文档验证,我们能用它来定义模式而不是用mongoose来定义模式吗.?例如:
Mongoose
userschema = mongoose.Schema({
org: String,
username: String,
fullname: String,
password: String,
email: String
});
MongoDB
db.createCollection(
"example",{
validator:{
$and:[
{ "org":{$type:"string"}},
{ "username":{$type:"string"}},
{ "fullname":{$type:"double"}},
{"password":$type:"string"}},
{"email":{$type:"string"}}
]
},
validationLevel:"strict",
validationAction:"error"
})
这两个选项之间有什么区别?我们可以像在模式中一样使用validator提供可选字段吗?