3.2.0 • Published 4 months ago

load-mongoose v3.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

load-mongoose

The established connection will use the default options (for mongoose 5.9), these can be overridden with mongoOpts:

useCreateIndex: true,
useFindAndModify: false,
useNewUrlParser: true,
useUnifiedTopology: true

Loading with independent params:

import loadMongoose from 'load-mongoose';
import { Connection } from 'mongoose';

mongoLoader({
  mongoAdditionalParams: 'authSource=admin',
  mongoDatabase: 'myapp',
  mongoHost: 'localhost',
  mongoOpts: {
    useCreateIndex: false
  },
  mongoPassword: 'password',
  mongoPort: 27017,
  mongoUser: 'username',
})
.then((connection: Connection) =>{
  // do something safe in the knowledge there is a connection to the db
})
.catch((e: any) => {
  // Do something with the error
});

Loading with full connection uri:

import loadMongoose from 'load-mongoose';
import { Connection } from 'mongoose';

loadMongoose({
  mongoOpts: {
    useCreateIndex: false
  },
  mongoUri: 'someurlstring',
})
.then((connection: Connection) =>{
  // do something safe in the knowledge there is a connection to the db
})
.catch((e: any) => {
  // Do something with the error
});

You can also import calculateConnectionUri from this lib to calculate a connection uri based on config objects, usefull for testing

import { calculateConnectionUri } from 'load-mongoose';

const uri = calculateConnectionUri({
  mongoAdditionalParams: 'authSource=admin',
  mongoDatabase: 'myapp',
  mongoHost: 'localhost',
  mongoOpts: {
    useCreateIndex: false
  },
  mongoPassword: 'password',
  mongoPort: 27017,
  mongoUser: 'username',
});

See the index.d.ts file for type definition mongoLoader 1st argument.

3.2.0

4 months ago

3.1.0

8 months ago

3.0.0

8 months ago

2.1.0

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago