Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-242

MongoDB update JsonValidator with NodeJS keeps failing

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker - P1
    • Resolution: Declined
    • Affects Version/s: None
    • Fix Version/s: No version
    • Component/s: None
    • Environment:
      MongoDB Atlas
    • # Replies:
      3
    • Last comment by Customer:
      true

      Description

      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:

      { address: 'adfadfslkds@ffk.co.uk', contactTypes: [ 'p', 'b' ], isPrimary: true, dateCreated: 1591981465 }

      }, {
      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" :

      { "hash" : BinData(0,"9QzeeWQw4kYtnf1m/2dTyvNphAQ="), "keyId" : NumberLong("6798592801870184449") }

      }
      } :
      _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. 

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            stephen.isienyi@gmail.com Stephen Isienyi
            Participants:
            Last commenter:
            Jessica Sigafoos Jessica Sigafoos
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since reply:
              1 year, 6 weeks, 2 days ago
              Date of 1st Reply: