Sample Header Ad - 728x90

"Document Failed Validation" what is wrong with my schema validation

0 votes
0 answers
900 views
I am trying to create a collection with JsonSchema (really its "BsonSchema") validation. This is a document that I want to insert (with bogus values). Note that Id is coming from the mongo c# driver as the ObjectID via StringObjectIdGenerator. { "_id": "60300d5d756a0b91278f2a3d", "UserId": 2, "UserName": "UserName_1", "Password": "Password_1", "PasswordSalt": "InstallSchema", "CreatedDateUtc": "2021-02-19T19:11:22.6438703Z" } This is the latest of the many schemas that I have tried to use. { "bsonType": "object", "properties": { "_id": { "bsonType": "string" }, "UserId": { "bsonType": "int" }, "UserName": { "bsonType": "string" }, "Password": { "bsonType": "string" }, "PasswordSalt": { "bsonType": "string" }, "CreatedDateUtc": { "bsonType": "date" } }, "required": ["_id", "UserId", "UserName", "Password", "PasswordSalt", "CreatedDateUtc" ] } When inserting the document into the collection it reports "Document failed validation" with no more specific detail. I know the document is correct, its the schema that is not, but I cant figure out what is wrong with it. I've tried different variations of the Id property including _id, as an objectid type, and removing it completely, but I dont know if thats even the problem. Any ideas on how to figure this out? Also I did try creating the collection without schema validation and the document inserts fine. Then in Compass, I ran analysis for the collection and exported what it calls a schema (a very different format from the validator schema) and the properties and types match the schema above.
Asked by StingyJack (101 rep)
Feb 19, 2021, 05:59 PM
Last activity: Feb 21, 2021, 10:26 PM