How to find all invalid document based on jsonSchema validator?
You can use the $jsonSchema query operator to find relevant documents.
For example, using the mongo shell:
// Retrieve the current validator for the &quot;students&quot; collection
var schema = db.getCollectionInfos({ name: &quot;students&quot; })[0].options.validator

// Find any documents not matching the schema
db.students.find({ $nor: [schema] })

Similarly, you can use the $jsonSchema query operator to confirm expected matches before adding or updating the validator for a collection:
var schema = {
  $jsonSchema: {
    properties: {
      name: {
        bsonType: &quot;string&quot;,
        description: &quot;name&quot;,
      },
    },
    required: [&quot;name&quot;],
    bsonType: &quot;object&quot;,
  },
}

// Find documents matching schema
db.students.find(schema)