mongo-json-schema
This is a library for validating objects against a jsonSchema before inserting into (and after retrieving from) mongo.
Creating a schema object
var Schema = ;var schema = ;
Validating an input object
schema// throws errors if its not valid!
Getting a standard jsonSchema
schema;
returns:
type: 'object' properties: _id: type: "string" pattern: "^[a-fA-F0-9]{24}$" required: true nested: type: 'object' properties: sub: type: "string" pattern: "^[a-fA-F0-9]{24}$" count: type: "number" required: false participants: type: "array" items: type: "string" pattern: "^[a-fA-F0-9]{24}$"
getting an object with strings for ids
schema;
returns:
_id: '52f044dee2896a8264d7ec2f' nested: sub: '52f044dee2896a8264d7ec2f' count: 42 participants: '52f044dee2896a8264d7ec2f''52f044dee2896a8264d7ec2f'
getting an object with ObjectIDs for ids
schema;
returns:
_id: nested: sub: count: 42 participants: