Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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架构失败_Mongodb - Fatal编程技术网

验证MongoDB架构失败

验证MongoDB架构失败,mongodb,Mongodb,使用MongoDB v3.6.2,我试图设计一个模式验证(它最终将包含比下面详述的更多的值)。我当前的布局具有以下结构: 模式 db.createCollection("Products", { validator: { $jsonSchema: { bsonType: "object", required: ["ProductId", "ProductName",

使用MongoDB v3.6.2,我试图设计一个模式验证(它最终将包含比下面详述的更多的值)。我当前的布局具有以下结构:

模式

db.createCollection("Products", {
    validator: {
        $jsonSchema: {
            bsonType: "object",
            required: ["ProductId",
                       "ProductName",
                       "Bonus.PremiumRate",
                       "Bonus.InterestRate",
                       "SurrChargeRates.First",
                       "SurrChargeRates.Second",
                       "SurrChargeRates.Third"],
            properties: {
                "ProductId": {
                    bsonType: "int",
                    description: "Must be a numerical representation of ID"
                },
                "ProductName": {
                    bsonType: "string",
                    description: "Must be a string representation of Product Name"
                },
                "Bonus.PremiumRate": {
                    bsonType: "decimal",
                    description: "Must be a decimal representation of Premium Rate Bonus"
                },
                "Bonus.InterestRate": {
                    bsonType: "decimal",
                    description: "Must be a decimal representation of Interest Rate Bonus"
                },
                "SurrChargeRates.First": {
                    bsonType: "decimal",
                    description: "Must be a decimal representation of First Surrender Charge Rate"
                },
                "SurrChargeRates.Second": {
                    bsonType: "decimal",
                    description: "Must be a decimal representation of Second Surrender Charge Rate"
                },
                "SurrChargeRates.Third": {
                    bsonType: "decimal",
                    description: "Must be a decimal representation of Third Surrender Charge Rate"
                }
            }
        }
    },
    validationLevel: "strict",
    validationAction: "error"
});
MongoDB接受了这一点,并成功创建了集合和验证。但是,当我尝试插入文档时,遇到错误代码121,
文档验证失败

我目前正在尝试的插入操作如下所示:

插入

db.Products.insert({
    "ProductId": NumberInt(1), 
    "ProductName": "Product Name",
    "Bonus.PremiumRate": NumberDecimal("0.3"),
    "Bonus.InterestRate": NumberDecimal("0.5"),
    "SurrChargeRates.First": NumberDecimal("0.1"),
    "SurrChargeRates.Second": NumberDecimal("0.1"),
    "SurrChargeRates.Third": NumberDecimal("0.1")
});
我还尝试了这个
insert
否定所有
numberprint
NumberDecimal
标记,没有任何改变。此外,设置
validationAction:“warn”
允许插入文档,但不是所需的功能。同样,从
required
对象中删除所有项目


此架构设计当前存在什么问题?

请尝试以下命令:

db.Products.insert({
    "ProductId": NumberInt(1), 
    "ProductName": "Product Name",
    "Bonus" : {
        "PremiumRate": NumberDecimal("0.3"),
        "InterestRate": NumberDecimal("0.5")
    },
    "SurrChargeRates":{
        "First": NumberDecimal("0.1"),
        "Second": NumberDecimal("0.1"),
        "Third": NumberDecimal("0.1")
    }
});

失败的原因是点表示法<代码>子文档应如上插入。

好吧!这非常有效。我假设点符号可以工作,因为它被用于架构的构建。非常感谢。