mongo-schemer
Detailed schema validation error messages for Mongo
Last updated 6 months ago by bgschiller .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mongo-schemer 
SYNC missed versions from official npm registry.

mongo-schemer

Provides clear Mongo schema validation error messages by running all validation errors through ajv. Does this by wrapping your Mongo client db in order to catch validation errors and compare against your schema.

Requirements

Installation

npm install mongo-schemer

Usage

Wrap your db with MongoSchemer.explainSchemaErrors():

const { MongoClient } = require('mongodb');
const MongoSchemer = require('mongo-schemer');

MongoClient.connect(dbUrl).then((client) => {
  const db = client.db(dbName);
  if (process.env.DEV) {
    db = MongoSchemer.explainSchemaErrors(db, {
      onError: (errors) => { console.log(errors); },
    });
  }
});

Running in prod is not recommended due to the overhead of validating documents against the schema.

Caveats

MongoDB does not currently support definitions in the JSON Schema. However, there is an easy workaround using json-schema-ref-parser. See https://brianschiller.com/blog/2018/01/30/pokemon-mongo-schemer for more information.

Current Tags

  • 1.0.8                                ...           latest (6 months ago)

9 Versions

  • 1.0.8                                ...           6 months ago
  • 1.0.7                                ...           6 months ago
  • 1.0.6                                ...           6 months ago
  • 1.0.5                                ...           7 months ago
  • 1.0.4                                ...           a year ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (11)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |