Create Collection with validator
db.createCollection(\"claims\",
{ validator : { $jsonSchema : { bsonType : \"object\",
As at MongoDB 3.6.2, JSON Schema validation does not automatically add the default _id
property, so you need to include a rule for this when using additionalProperties: false
.
For example, assuming the default ObjectID:
db.createCollection("claims",
{ validator : {
$jsonSchema : {
bsonType : "object",
properties : {
_id: { bsonType: "objectId" },
airportCode : { bsonType: "string"}
},
additionalProperties: false
}
}}
)
Two related issues to upvote/watch on the MongoDB Jira issue tracker: