Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-60708

db.collection.validate() returns `nInvalidDocuments: 0` when invalid documents are present

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.0.0-rc0
    • Affects Version/s: 5.0.2, 5.0.3
    • Component/s: None
    • Fully Compatible
    • ALL
    • Hide
      use test
      db.runCommand( { "drop": "testValidation" } )
      db.createCollection("testValidation", {
          "validationLevel": "strict",
          "validationAction": "warn",
          "validator": { "$jsonSchema": {
                                        "required": [
                                          "foo"
                                        ],
                                        "properties": {
                                          "foo": {
                                            "bsonType": "string"
                                          }
                                        }
                                      }
          }
      })
      db.testValidation.insertMany([
          { "foo": "bar" },
          { "quux": "fizz" }
      ])
      db.testValidation.validate() // logs a warning but does not include it in validation response
      db.runCommand( { "collMod": "testValidation", "validationAction": "error" } ) 
      db.testValidation.validate() // logs a warning, includes warning in validation response, but nInvalidDocuments=0
      
      Show
      use test db.runCommand( { "drop" : "testValidation" } ) db.createCollection( "testValidation" , {     "validationLevel" : "strict" ,     "validationAction" : "warn" ,     "validator" : { "$jsonSchema" : {                                   "required" : [                                     "foo"                                   ],                                   "properties" : {                                     "foo" : {                                       "bsonType" : "string"                                     }                                   }                                 }     } }) db.testValidation.insertMany([     { "foo" : "bar" },     { "quux" : "fizz" } ]) db.testValidation.validate() // logs a warning but does not include it in validation response db.runCommand( { "collMod" : "testValidation" , "validationAction" : "error" } ) db.testValidation.validate() // logs a warning, includes warning in validation response, but nInvalidDocuments=0
    • Execution Team 2022-04-04

      If I create a collection with validationLevel: strict and validationAction: warn, and subsequently run db.collection.validate() on a collection containing invalid documents, I would expect the number of invalid documents and the warnings array to be populated

      However, running `db.collection.validate()` on a collection with invalid documents returns unexpected results:

      • nInvalidDocuments is 0
      • and no messages present in the warnings[] or errors[] array

      The logs for the server do log the errors, but the errors are not reflected in the output to db.collection.validate().

      If I use validationAction: error, then execute `db.collection.validate()`, there is a warning present in warnings[] but nInvalidDocuments is still 0.

            Assignee:
            gregory.wlodarek@mongodb.com Gregory Wlodarek
            Reporter:
            emetsger@gmail.com Elliot Metsger
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: