Reputation: 329
I have written the validation for one of my collection. I am inserting document in mongodb atlas accordingly but still its is saying validation error.
Validation
{
$jsonSchema: {
bsonType: 'object',
additionalProperties: false,
required: [
'userName'
],
properties: {
userName: {
bsonType: 'string',
description: 'asdasdasdasdasdasdasd'
}
}
}
}
Insert
/** * Paste one or more documents here*/
{
"_id": {
"$oid": "605e144151348bafd4b9c0e2"
},
"userName":"asdasdasd"
}
Upvotes: 0
Views: 678
Reputation: 28356
The defined schema permits only the namespace
field, and disallows any other fields.
MongoDB cannot store a document without a field named _id
, since that is not permitted by the validation, no document can be inserted.
Upvotes: 1