load-mongoose

Loads a mongodb connection for mongoose..,

Usage no npm install needed!

<script type="module">
  import loadMongoose from 'https://cdn.skypack.dev/load-mongoose';
</script>

README

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';

mongoLoader({
  mongoAdditionalParams: 'authSource=admin',
  mongoDatabase: 'myapp',
  mongoHost: 'localhost',
  mongoOpts: {
    useCreateIndex: false
  },
  mongoPassword: 'password',
  mongoPort: 27017,
  mongoUser: 'username',
})
.then(() =>{
  // 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';

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

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