title: Mongo Json Schema Validator AnyOf not working
body: <p>I have created the a collection with the below validation:</p>
  
  <pre><code>{
    $jsonSchema: {
      bsonType: 'object',
      additionalProperties: false,
      properties: {
        _id: {
          bsonType: 'objectId'
        },
        test: {
          bsonType: 'string'
        }
      },
      anyOf: [
        {
          bsonType: 'object',
          properties: {
            test1: {
              bsonType: 'string'
            }
          },
          additionalProperties: false
        },
        {
          bsonType: 'object',
          properties: {
            test2: {
              bsonType: 'string'
            }
          },
          additionalProperties: false
        }
      ]
    }
  }
  </code></pre>
  
  <p>The Validation Action was set to Error and Validation Level to Moderate.</p>
  
  <p>When I try to insert a document containing the field <strong>test</strong> and <strong>test1</strong>, I am getting a validation error</p>
  
  <pre><code>Document:
  db.dmt9.insert([{test:"123"},{test1:"456"}])
  
  Error:
  
  BulkWriteResult({
          "writeErrors" : [
                  {
                          "index" : 0,
                          "code" : 121,
                          "errmsg" : "Document failed validation",
                          "op" : {
                                  "_id" : ObjectId("5dd511de1f7b2047ed527044"),
                                  "test" : "123"
                          }
                  }
          ],
          "writeConcernErrors" : [ ],
          "nInserted" : 0,
          "nUpserted" : 0,
          "nMatched" : 0,
          "nModified" : 0,
          "nRemoved" : 0,
          "upserted" : [ ]
  })
  </code></pre>
  
  <p>Since I am inserting a document containing one of the fields inside the AnyOf, shouldn't the document be inserted successfully?  If I try and change the Validation Action to  Warning, the document is inserted however I can insert any other field.</p>
  
  <pre><code>Test with validation Action - Warning
  
  rs0:PRIMARY&gt; db.dmt9.insert([{test:"123"},{test1:"456"},{test9:123}])
  BulkWriteResult({
          "writeErrors" : [ ],
          "writeConcernErrors" : [ ],
          "nInserted" : 3,
          "nUpserted" : 0,
          "nMatched" : 0,
          "nModified" : 0,
          "nRemoved" : 0,
          "upserted" : [ ]
  })
  </code></pre>
  
  <p><strong>Update 2:</strong>
  When I remove the field test I get this validator:</p>
  
  <pre><code>{
    $jsonSchema: {
      bsonType: 'object',
      additionalProperties: false,
      anyOf: [
        {
          bsonType: 'object',
          properties: {
            test1: {
              bsonType: 'string'
            }
          },
          additionalProperties: false
        },
        {
          bsonType: 'object',
          properties: {
            test2: {
              bsonType: 'string'
            }
          },
          additionalProperties: false
        }
      ],
      properties: {
        _id: {
          bsonType: 'objectId'
        }
      }
    }
  }
  </code></pre>
  
  <p>and when i try to insert test1 again I still get the error message Document failed validation</p>
  
  <pre><code>rs0:PRIMARY&gt; db.dmt8.insert([{test1:"123"}])
  BulkWriteResult({
          "writeErrors" : [
                  {
                          "index" : 0,
                          "code" : 121,
                          "errmsg" : "Document failed validation",
                          "op" : {
                                  "_id" : ObjectId("5dd51b4766ba25a01fbcf8e6"),
                                  "test1" : "123"
                          }
                  }
          ],
          "writeConcernErrors" : [ ],
          "nInserted" : 0,
          "nUpserted" : 0,
          "nMatched" : 0,
          "nModified" : 0,
          "nRemoved" : 0,
          "upserted" : [ ]
  })
  </code></pre>