-
Type: Bug
-
Resolution: Won't Do
-
Priority: Blocker - P1
-
Affects Version/s: None
-
Component/s: None
-
Environment:MongoDB Atlas
Json validation for my db update/upsert operations keeps failing. Updates are only successful when I remove the db.createCollection validator option parameter. But schema validation is crucial for this use-case so development is currently at a halt and 3 days have been lost as a result.
Schema
{ additionalProperties: false, bsonType: 'object', description: 'email data point', properties: { _id: { bsonType: 'objectId' }, address: { bsonType: 'string', maxLength: 64, pattern: '^\w+@\w+(.\w+)+$', description: 'required: email address' }, contactTypes: { bsonType: 'array', description: 'required: a set of unique string values', items: { bsonType: 'string', enum: email.map( e => e.value ) }, uniqueItems: true }, dateCreated: { bsonType: 'long', description: 'required: contact email creation timestamp in ms since epoch' }, isPrimary: { bsonType: 'bool' }, lastUpdated: { bsonType: 'long', description: 'contact email recent update timestamp in ms since epoch' } }, required: [ 'address', 'contactTypes', 'dateCreated', 'isPrimary' ] }{{}}
Shell call:
MongoDB Enterprise D0-shard-0:PRIMARY> db.emails.findOneAndUpdate({
address: 'adfadfslkds@ffk.co.uk',
contactTypes: [ 'p', 'b' ],
isPrimary: true
}, {
$set:
}, {
returnNewDocument: true,
upsert: true
})
Result:
2020-06-12T12:33:47.785-0700 E QUERY [js] uncaught exception: Error: findAndModifyFailed failed: {
"operationTime" : Timestamp(1591990428, 24),
"ok" : 0,
"errmsg" : "Document failed validation",
"code" : 121,
"codeName" : "DocumentValidationFailure",
"$clusterTime" : {
"clusterTime" : Timestamp(1591990428, 24),
"signature" :
}
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DBCollection.prototype.findAndModify@src/mongo/shell/collection.js:725:15
DBCollection.prototype.findOneAndUpdate@src/mongo/shell/crud_api.js:900:12
@(shell):1:1
Thanks in advance for looking into this issue.