mongo-validator
MongoDB JSON to Validator
Usage example
const mongoValidator = ; const payload = __size: 10 foo: '!String' bar: 'Number' customObject: __exists: true propTest: 'Bool' ; const validatorPayload = ;console;
It will log (stdout) the following result :
{
"validator": {
"$and": [
{
"foo": {
"$type": "string",
"$exists": true
}
},
{
"bar": {
"$type": "number"
}
},
{
"customObject": {
"$type": "object",
"$exists": true
}
},
{
"customObject.propTest": {
"$type": "bool"
}
}
]
},
"size": 10
}
Use this object as a validator for MongoDB (when you create a new collection for example).