@ladjs/mongoose

Mongoose helper for Lad

Usage no npm install needed!

<script type="module">
  import ladjsMongoose from 'https://cdn.skypack.dev/@ladjs/mongoose';
</script>

README

@ladjs/mongoose

build status code coverage code style styled with prettier made with lass license

Mongoose helper for Lad

Table of Contents

Install

npm:

npm install @ladjs/mongoose mongoose

yarn:

yarn add @ladjs/mongoose mongoose

Requires mongoose v6 to be a dependency in your project.

Usage

This package is a mongoose connection helper that sets up some sensible default connection options for mongoose and event dubugging helpers.

The default options are outlined below.

This package also provides reconnection logic on the initial connection. This is especcially convenient as this is not baked into mongo or mongoose natively. Mongoose will, however, take over reconnection in the event there is a disconnect event.

Usage:

const Mongoose = require('@ladjs/mongoose');
const mongoose = new Mongoose({
  // ...
});

(async () => {
  await mongoose.connect();
})();

Now require and use the mongoose singleton in the rest of your project as you normally would.

const mongoose = require('mongoose');

Options

Option Type Default Description
mongo Object {} mongoose connection options
which are passed to mongo
see mongo options docs
reconnectTries Number Number.MAX_VALUE How many times @ladjs/mongoose will attempt to create the initial connection
reconnectInterval Number 1000 Time in ms between initial connection attempts
debug Boolean false set with mongoose.set
bufferCommands Boolean undefined set with mongoose.set
cloneSchemas Boolean undefined set with mongoose.set
applyPluginsToDiscriminators Boolean undefined set with mongoose.set
applyPluginsToChildSchemas Boolean undefined set with mongoose.set
objectIdGetter Boolean undefined set with mongoose.set
runValidators Boolean undefined set with mongoose.set
toObject Boolean undefined set with mongoose.set
toJSON Boolean undefined set with mongoose.set
strict Boolean undefined set with mongoose.set
strictQuery Boolean undefined set with mongoose.set
selectPopulatedPaths Boolean undefined set with mongoose.set
maxTimeMS Boolean undefined set with mongoose.set
autoIndex Boolean undefined set with mongoose.set
autoCreate Boolean undefined set with mongoose.set
overwriteModels Boolean undefined set with mongoose.set

Contributors

Name Website
Nick Baugh http://niftylettuce.com
Spencer Snyder http://spencersnyder.io

License

MIT © Nick Baugh