MongoDB验证失败
我使用了MongoDB的验证规则,但是每次插入都会失败MongoDB验证失败,mongodb,Mongodb,我使用了MongoDB的验证规则,但是每次插入都会失败 db.createCollection("mycollection",{ validator:{ $and:[ {name: {$type:"string"}}, {age: {$type:"int"}} ] }}) 添加条目时 db.mycollection.insertOne({name:"Joseph", age: 18}) 但我总是得到一个错误,一个通用消息文档验证失败。
db.createCollection("mycollection",{
validator:{
$and:[
{name: {$type:"string"}},
{age: {$type:"int"}}
]
}})
添加条目时
db.mycollection.insertOne({name:"Joseph", age: 18})
但我总是得到一个错误,一个通用消息文档验证失败。
有什么想法吗?
谢谢。在mongodb中,int的默认类型是Double。 所以,您可以在验证规则中设置类型Double,或者尝试
db.mycollection.insertOne({name:"Joseph", age: NumberInt(18)}))
在mongodb中,int的默认类型是Double。 所以,您可以在验证规则中设置类型Double,或者尝试
db.mycollection.insertOne({name:"Joseph", age: NumberInt(18)}))
非常感谢。MongoDB的决定毫无意义,因为Number.isInteger18是正确的。谢谢!MongoDB的这个决定毫无意义,因为Number.isInteger18是真的。