New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongo-schemer

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongo-schemer

Detailed schema validation error messages for Mongo

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

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

  • Your schema validation has to be in $jsonSchema format. More info here: https://docs.mongodb.com/manual/core/schema-validation/
  • Currently only supports Promise-based usage of Mongo. PRs welcome!

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.

FAQs

Package last updated on 06 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc