I created a collection with validation rules using the following syntax:
>db.createCollection("CollName", {
validator: {
$jsonSchema:
{
bsonType: "object",
properties: {
a1: {
bsonType: "string",
},
a2:{
bsonType: "string",
},
a3: {
bsonType: "array",
items: {
bsonType: "object",
properties: {
b1: {
bsonType: "string",
},
b2: {
bsonType: "string",
}
}
}
}
}
}
}})
And I want to insert some documents into it. However, I am not able to find the correct syntax. I tried the following:
> db.CollName.insert({
... a1:"122234343",
... a2: "name1",
... a3: [b1: "aaa1111", b2: "bbb222"]
... })
2020-05-28T12:33:50.052+0200 E QUERY [js] uncaught exception: SyntaxError: missing ] after element list :
@(shell):4:8
> db.CollName.insert({
... a1:"122234343",
... a2: "name1",
... a3: ["aaa1111", "bbb222"]
... })
WriteResult({
"nInserted" : 0,
"writeError" : {
"code" : 121,
"errmsg" : "Document failed validation"
}
})
How can I find the correct syntax?