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?