With schema validation, can you query documents that don't match?

Let’s say I configure a $schema validation rule for my collection.

If I set the Validation level to off (so update/insert will work no matter what)
Screen Shot 2022-05-23 at 11.51.31

How can I query a list of documents that pass/fail the schema validation?

Hi @Alex_Bjorlig,

You can use the $jsonSchema operator to find existing documents that that match (or do not match) a JSON schema validator.

There are some examples in the Query Conditions section of the $jsonSchema operator documentation.


1 Like

Ahh thanks @Stennie !

Now that I have your attention, could I politely ask if you have Typescript <–> JSON Schema expertise - or maybe know someone at MongoDB?

Our team is still debating how to maintain Typescript interfaces and MongoDB JSON schemas. I tried to ask for inputs here, but to my surprise nobody answered :sweat_smile:

I imagine this is a task everyone using Typescript/Mongodb-schema-validation would have, but there is supringsly few results when I google this.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.