Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb Mongo db验证规则使我的insert语句失败_Mongodb_Validation_Nosql - Fatal编程技术网

Mongodb Mongo db验证规则使我的insert语句失败

Mongodb Mongo db验证规则使我的insert语句失败,mongodb,validation,nosql,Mongodb,Validation,Nosql,这对我来说有点奇怪,我是mongo db的新手 我通过NoSQLBoster控制台设置了以下验证规则: let validator = [ {language : { $type : "string", $exists : true }}, {label : { $type : "string", $exists : true }}, {text : { $type : "st

这对我来说有点奇怪,我是mongo db的新手

我通过NoSQLBoster控制台设置了以下验证规则:

let validator = [
    {language : {
        $type : "string",
        $exists : true
    }},
    {label : {
        $type : "string",
        $exists : true
    }},
    {text : {
        $type : "string",
        $exists : true
    }},
    {order : {
        $type : "int",
        $exists : true
    }}
  ];

db.runCommand( {
  collMod: "profile",
  validator,
  validationLevel: "moderate", //off | strict
  //validationAction: "warn" |"error"
})
那么,在添加验证程序之后,我尝试添加以下文档:

db.profile.insert({language: 'en', label: 'Born', text: '31 Dec 1983 - Jaén, Spain', order: 1})
我假装所有这些字段都是强制性的。即使提供了所有这些类型并具有适当的类型,我始终会遇到以下插入错误:

{
"message" : "write failed with error: {" +
          "    'nInserted' : 0," +
          "    'writeError' : {" +
          "    \t'code' : 121," +
          "    \t'errmsg' : 'Document failed validation'" +
          "    }" +
          "}",
"stack" : "script:1:96" +
          "script:1:96" +
          "script:1:96" +
          "script:1:96",
"code" : {
    "nInserted" : 0,
    "nUpserted" : 0,
    "nMatched" : 0,
    "nModified" : 0,
    "nRemoved" : 0
}
}
现在它变成了好奇心。。。 我做错了什么


谢谢你抽出时间

我解决了我的问题。我只需要使用numberprint函数来包装整数。否则,它将被视为浮点数。以下各项工作如期进行:

db.profile.insert({language: 'en', label: 'Born', text: '31 Dec 1983 - Jaén, Spain', order: NumberInt(1)})

谢谢大家!

我解决了我的问题。我只需要使用numberprint函数来包装整数。否则,它将被视为浮点数。以下各项工作如期进行:

db.profile.insert({language: 'en', label: 'Born', text: '31 Dec 1983 - Jaén, Spain', order: NumberInt(1)})
谢谢大家!

这是设计的

细节

来源:

这是设计的

细节

资料来源: