Validation of Date type failed when working with mongodb driver in Nodejs

Hi everyone, I am working with mongodb driver recently, and I am struggling working with $jsonSchema. I have a $jsonSchema here:

validator: {
    $jsonSchema: {
        bsonType: 'object',
        required: ['email', 'username', 'password', 'avatar', 'gender', 'createdAt'],
        properties: {
            email: { bsonType: 'string' },
            username: { bsonType: 'string' },
            password: { bsonType: 'string' },
            avatar: { bsonType: 'bool' },
            gender: { bsonType: ['string', 'null'], enum: ['male', 'female', 'other', 'rather not to say'] },
            createdAt: { bsonType: 'date' }
        }
    }
}

When I try to insert new record, it throws an error of document failed validation. I have made a little bit search on google, and it seems being weird.
Here is my record inserted:

const newUser = {
    email: email,
    username: username,
    password: bcrypt.hashSync(password, 10),
    avatar: false,
    gender: null,
    createdAt: new Date()
}

After many time of trying, I have noted that the problem is createdAt but I am not sure why. Do you have any idea?

@john-silver what’s the actual error? The error details should make it a bit clearer as to which field is failing.

For example:

MongoServerError: Document failed validation
Additional information: {
  failingDocumentId: ObjectId("65662386abdbda8139abd083"),
  details: {
    operatorName: '$jsonSchema',
    schemaRulesNotSatisfied: [
      {
        operatorName: 'required',
        specifiedAs: { required: [ 'createdAt' ] },
        missingProperties: [ 'createdAt' ]
      }
    ]
  }
}