6.0.1 • Published 1 year ago

@ladjs/mongoose v6.0.1

Weekly downloads
24
License
MIT
Repository
github
Last release
1 year ago

@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

OptionTypeDefaultDescription
loggerObjectconsoleCustom logger function, see cabin or axe as a default if desired.
mongoObject---See below uri and options properties.
mongo.uriStringundefinedmongo connection URI which is passed as the first argument to mongoose.createConnection see mongo options docs
mongo.optionsObjectundefinedmongo connection options which is passed as the second argument to mongoose.createConnection see mongo options docs
bindEventsBooleantrueWhether or not to bind default events to the Mongoose connection using provided logger.
hideMetaString 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.
------------
allowDiskUseBooleanundefinedset with mongoose.set
applyPluginsToChildSchemasBooleanundefinedset with mongoose.set
applyPluginsToDiscriminatorsBooleanundefinedset with mongoose.set
autoCreateBooleanundefinedset with mongoose.set
autoIndexBooleanundefinedset with mongoose.set
bufferCommandsBooleanundefinedset with mongoose.set
bufferTimeoutMSBooleanundefinedset with mongoose.set
debugBooleanIf process.env.MONGOOSE_DEBUG is truthy, then it is true, otherwise falseset with mongoose.set
idBooleanundefinedset with mongoose.set
timestamps.createdAt.immutableBooleanundefinedset with mongoose.set
maxTimeMSNumber10000set with mongoose.set
objectIdGetterBooleanundefinedset with mongoose.set
overwriteModelsBooleanundefinedset with mongoose.set
returnOriginalBooleanundefinedset with mongoose.set
runValidatorsBooleanundefinedset with mongoose.set
sanitizeFilterBooleanundefinedset with mongoose.set
selectPopulatedPathsBooleanundefinedset with mongoose.set
strictBooleantrueset with mongoose.set
strictQueryBooleantrueset with mongoose.set
toJSONBooleanundefinedset with mongoose.set
toObjectBooleanundefinedset with mongoose.set

Contributors

NameWebsite
Nick Baughhttp://niftylettuce.com
Spencer Snyderhttp://spencersnyder.io

License

MIT © Nick Baugh

5.0.6

1 year ago

5.0.5

1 year ago

5.0.4

1 year ago

5.0.3

1 year ago

5.0.2

1 year ago

5.0.1

1 year ago

5.0.10

1 year ago

5.0.0

1 year ago

6.0.1

1 year ago

6.0.0

1 year ago

5.0.9

1 year ago

5.0.8

1 year ago

5.0.7

1 year ago

4.0.1

1 year ago

4.0.0

1 year ago

4.0.2

1 year ago

3.0.0

3 years ago

2.1.1

4 years ago

2.0.2

4 years ago

2.1.0

4 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago