npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ladjs/mongoose

v7.0.0

Published

Mongoose helper for Lad, which is used as an alternative to the default `mongoose.connect()` for multiple connection management. See the Forward Email codebase for further insight into setup.

Downloads

394

Readme

@ladjs/mongoose

build status code style styled with prettier made with lass license

Mongoose helper for Lad, which is used as an alternative to the default mongoose.connect() for multiple connection management. See the Forward Email codebase for further insight into setup.

Table of Contents

Install

Requires mongoose v6+ to be a dependency in your project.

npm:

npm install @ladjs/mongoose mongoose

Usage

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

(async () => {
  const m = new Mongoose({
    mongo: {
      options: { heartbeatFrequencyMS: 100, serverSelectionTimeoutMS: 1000 }
    }
  });

  const conn1 = await m.createConnection('mongodb://server-one.example.com/database-name').asPromise();
  const conn2 = await m.createConnection('mongodb://server-two.example.com/database-name').asPromise();

  const UserSchema = new Schema({ name: String });
  const LogSchema = new Schema({ name: String });

  const Users = conn1.model('Users', UserSchema);
  const Logs = conn2.model('Logs', LogSchema);

  // write to the server-one.example.com database
  await Users.create({ name: 'test' });

  // write to the server-two.example.com database
  await Logs.create({ name: 'test' });
})();

Note that instances of this class Mongoose only have the method createConnection. It is not 1:1 with mongoose normal singleton.

You should use @ladjs/graceful to manage process SIGHUP and graceful exits.

Options

| Option | Type | Default | Description | | -------------------------------- | ------------------------- | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | logger | Object | console | Custom logger function, see cabin or axe as a default if desired. | | mongo | Object | --- | See below uri and options properties. | | mongo.uri | String | undefined | mongo connection URI which is passed as the first argument to mongoose.createConnection see mongo options docs | | mongo.options | Object | undefined | mongo connection options which is passed as the second argument to mongoose.createConnection see mongo options docs | | bindEvents | Boolean | true | Whether or not to bind default events to the Mongoose connection using provided logger. | | hideMeta | String or false Boolean | "hide_meta" | Appends a true boolean property to a property with this value in logs, e.g. console.log('mongoose disconnected', { hide_meta: true }); which is useful for preventing metadata object from being invoked as the second argument (this is meant for usage with Cabin and Axe and made for Forward Email). If you pass a false value then this property will not get populated. | | --- | --- | --- | --- | | allowDiskUse | Boolean | undefined | set with mongoose.set | | applyPluginsToChildSchemas | Boolean | undefined | set with mongoose.set | | applyPluginsToDiscriminators | Boolean | undefined | set with mongoose.set | | autoCreate | Boolean | undefined | set with mongoose.set | | autoIndex | Boolean | undefined | set with mongoose.set | | bufferCommands | Boolean | undefined | set with mongoose.set | | bufferTimeoutMS | Boolean | undefined | set with mongoose.set | | debug | Boolean | If process.env.MONGOOSE_DEBUG is truthy, then it is true, otherwise false | set with mongoose.set | | id | Boolean | undefined | set with mongoose.set | | timestamps.createdAt.immutable | Boolean | undefined | set with mongoose.set | | maxTimeMS | Number | 10000 | set with mongoose.set | | objectIdGetter | Boolean | undefined | set with mongoose.set | | overwriteModels | Boolean | undefined | set with mongoose.set | | returnOriginal | Boolean | undefined | set with mongoose.set | | runValidators | Boolean | undefined | set with mongoose.set | | sanitizeFilter | Boolean | undefined | set with mongoose.set | | selectPopulatedPaths | Boolean | undefined | set with mongoose.set | | strict | Boolean | true | set with mongoose.set | | strictQuery | Boolean | true | set with mongoose.set | | toJSON | Boolean | undefined | set with mongoose.set | | toObject | Boolean | undefined | set with mongoose.set |

Contributors

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

License

MIT © Nick Baugh