2016-10-22 57 views
0

验证我创造了一个在MongoDB中3.2没有得到错误信息,甚至有在MongoDB中

db.createCollection("contacts", 
    { 
     validator: { $or: 
     [ 
      { phone: { $type: "string" } }, 
      { email: { $regex: /@mongodb\.com$/ } }, 
      { status: { $in: [ "Unknown", "Incomplete" ] } } 
     ] 
     }, 
     validationAction: "error" 
    } 
) 

与下面的验证名为“联系人”之后收集我插入下面的文档后:

db.contacts.insert({ name: "Girish Gupta", status: "Updated" }) 
WriteResult({ "nInserted" : 1 }) 

有应该是一些错误,因为我没有插入有效的状态。 但我没有收到任何错误。

回答

0

我今天遇到了同样的问题。

事实上,美国商务部刚刚指出的正下方可能出现的问题:

Restrictions说:

您不能指定在管理藏品,本地验证器,并配置数据库。 您无法为系统。*集合指定验证程序。

Bypass Document Validation

...对于那些已经启用访问控制,绕过文档验证部署,通过验证的用户必须拥有bypassDocumentValidation行动。内置角色dbAdmin和restore提供了此操作。

所以,如果我们使用admin来操作,那肯定会有bypass的验证。只需添加一个新用户(不是管理员),并执行操作将得到预期的答案。

相关问题