JsonSchema validation fails to validate date type with enum

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Trivial - P5
    • None
    • Affects Version/s: 8.0.0
    • Component/s: None
    • None
    • Environment:
      Ubuntu 25, MongoDB 8, node 24, mongoDB NodeJS drivers 6.17.0
    • ALL
    • Hide

      create a mongodb collection named `user` with the following schema:

      {
        $jsonSchema: {
          bsonType: 'object',
          required: [
            'birthDate',
            '_id'
          ],
          properties: {
            birthDate:
      {         bsonType: 'date',         'enum': [           '1900-01-01T00:00:00.000Z',           '2000-01-01T00:00:00.000Z',         ]       }
      ,
            _id:
      {         bsonType: 'objectId'       }
          },
          additionalProperties: false
        }
      }
      

       
      then try to insert this document:

      {
        "_id":
      {     "$oid": "68544291c44bede24cdd1f9c"   }
      ,
        "birthDate":
      {     "$date": "2000-01-01T00:00:00.000Z"   }
      }
      

       

      Show
      create a mongodb collection named `user` with the following schema: {   $jsonSchema: {     bsonType: 'object' ,     required: [       'birthDate' ,       '_id'     ],     properties: {       birthDate: {         bsonType: 'date' ,         ' enum ' : [           '1900-01-01T00:00:00.000Z' ,           '2000-01-01T00:00:00.000Z' ,         ]       } ,       _id: {         bsonType: 'objectId'       }     },     additionalProperties: false   } }   then try to insert this document: {   "_id" : {     "$oid" : "68544291c44bede24cdd1f9c"   } ,   "birthDate" : {     "$date" : "2000-01-01T00:00:00.000Z"   } }  
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I'm trying to validate a date property against an `enum` within a JSONSchema.

      here is the JSONSchema:

      {
        $jsonSchema: {
          bsonType: 'object',
          required: [
            'birthDate',
            '_id'
          ],
          properties: {
            birthDate: {
              bsonType: 'date',
              'enum': [
                '1900-01-01T00:00:00.000Z',
                '2000-01-01T00:00:00.000Z',
              ]
            },
            _id: {
              bsonType: 'objectId'
            }
          },
          additionalProperties: false
        }
      }
      

      here is the validation error:

      {
        "failingDocumentId": "68543d9ec44bede24cdd1f9b",
        "details": {
          "operatorName": "$jsonSchema",
          "schemaRulesNotSatisfied": [
            {
              "operatorName": "properties",
              "propertiesNotSatisfied": [
                {
                  "propertyName": "birthDate",
                  "details": [
                    {
                      "operatorName": "enum",
                      "specifiedAs": {
                        "enum": [
                          "1989-02-21T00:00:00.000Z",
                          "2000-01-01T00:00:00.000Z"
                        ]
                      },
                      "reason": "value was not found in enum",
                      "consideredValue": "2000-01-01T00:00:00.000Z"
                    }
                  ]
                }
              ]
            }
          ]
        }
      }
      

      I've also tried to set the enum date as an epoch (integer) and a mongodb "json" date `

      {"$date": "2000-01-01T00:00:00.000Z"}

      `.
      None of these workarounds are working.

            Assignee:
            Kenan Ali
            Reporter:
            Nico P.
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: