Я новичок в MongoDB
, я написал schema validation
, но я не в состоянии insert
данные дают мне schema validation error
, код показан ниже, любая помощь будет принята с благодарностью.
валидатор:
db.createCollection("kartCollection", {
validator: {
$jsonSchema: {
bsonType: "object",
required: [ "uid", "items" ],
properties: {
uid: {
bsonType: "number",
description: "holds user id"
},
items: {
bsonType: "object",
required: [ "itemid","qty","qty_type","cost","currency" ],
properties: {
itemid: {
bsonType: "number",
description: "holds items id"
},
qty: {
bsonType: "number",
"description": "holds quantity of item"
},
qty_type: {
bsonType: "string",
"description": "holds quantity type like l,kl,kg gm,pcs"
},
cost: {
bsonType: "number",
"description": "holds cost of the selected item for quiker fetch"
},
currency: {
bsonType: "string",
"description": "holds currency of the item sold in "
}
}
}
}
}
}
});
db.kartCollection.insert({uid:'1',items:{{itemid:'1',qty:'1',qty_type:'kg',cost:'20',currency:'INR'}}});
Ошибка
WriteResult({
"nInserted" : 0,
"writeError" : {
"code" : 121,
"errmsg" : "Document failed validation"
}
})