Storing validator in MongoDB document

I'd like to have a flexible schema in Mongo, but would also like to enforce a schema for subsequent updates. Is it possible to store the validation in the document like the following? I have tried this, but can't seem to convert the string into a Joi object.

{
    "_id" : ObjectId("53d5dce1fc87899b2b3c2def"),
    "name" : {
        "validator" : "Joi.string().alphanum().min(3).max(30).required()",
        "value" : "Bob" 
    },
    "email" : {
        "validator" : "Joi.string().email()",
        "value" : "bob@gmail.com"
    }
}

Most of the time, storing executable code in a database is not a good idea. What will you do when you realize a validator function which is already stored in a billion documents needs to be modified? What if someone manages to insert a document with validation code which does more malicious stuff than just validating?

I would really recommend you to determine the type of the document and the appropriate validation routine for each type in node.js.

But when you insist on having executable code for each document in the document itself, you can run that code in node.js using the vm.runInContext(object.validator, object) method. Keep in mind that this requires access to the whole document in node.js, so you can not do partial updates. Also keep in mind that, as I said, it might not be a very good idea.