Skip to content

Latest commit

 

History

History
67 lines (49 loc) · 1.68 KB

README.md

File metadata and controls

67 lines (49 loc) · 1.68 KB

manggis

Mongoose schema and ref integrity validator

Motivation: create simple tool to validate mongoose schema and references integrity

How it works: It takes a mongoose connection instance from your code and interate thru each model and each document using async iterable interface provided by mongoose. Due to limitations of mongoose api, it will create custom model clone if verifyRefs option set to true to avoid mutating original model. This models will be automatically deleted later.

Additional features:

  • No external dependencies except mongoose as a peer dependency
  • Simple programmatic API allowing you to create any logging or data processing
  • Typescript typings

Installation

npm i -S manggis

Example (Typescript)

import { Connection } from 'mongoose';
import { validate } from 'manggis'

async function main() {
  /* !!! place your mongoose connection instance here !!! */
  const connection: Connection = {} as Connection

  await validate(connection, {
    onError: ({ model, path, message }) => {
      console.log(`    error [${model}.${path}]: ${message}`)
    },
    onModel(model) {
      console.log('validating model:', model.modelName);
    },
    onDocument(doc) {
      console.log('  validating document:', doc._id);
    }
  });

  console.log('all models has been verified');
  process.exit();
}

if (require.main === module) {
  main()
}

Contributions

Feel free to send PR's or suggest new features in Issues.