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

mongoose-connection-config

v0.2.5

Published

Helper library to set mongoose connection configuration.

Downloads

30

Readme

mongoose-connection-config

npm CircleCI Codecov

Helper library to set mongoose connection configuration.


Installation

$ npm install mongoose-connection-config --save

Usage

Build the connection string

const MongooseConnectionConfig = require('mongoose-connnection-config');

const opts = {
  host: process.env.MONGO_HOST || 'localhost',
  port: process.env.MONGO_PORT || 27017,
  database: 'my-db'
};
const mcc = new MongooseConnectionConfig(opts);

console.log(mcc.getMongoUri()); // => mongodb://localhost:27017/my-db

Override the connection string

If you want to ignore all options being passed in, then set the option connection_string, this value will then be returned, building the connection string will be skipped.


const MongooseConnectionConfig = require('mongoose-connnection-config');

const opts = {
  connection_string: 'mongodb+srv://dbUser:[email protected]/test?retryWrites=true&w=majority',
  host: process.env.MONGO_HOST || 'localhost',
  port: process.env.MONGO_PORT || 27017,
  database: 'my-db'
};
const mcc = new MongooseConnectionConfig(opts);

console.log(mcc.getMongoUri()); // => mongodb+srv://dbUser:[email protected]/test?retryWrites=true&w=majority

API

MongooseConnectionConfig

Configuration

Define a configuration object to pass to the constructor.

If no options are defined, the default options will be used: See index.js => DEFAULT_CONFIGURATION for more information about the current default options.

Params

  • opts {Object}: Options to pass in.
  • {String}: `opts.connection_string - Full connection string which will then be returned, ignoring all other options.
  • opts.debug {Boolean}: Whether MongoDB runs in debug mode or not.
  • opts.host {String}: The MongoDBhost, defaults to localhost. See the mongodb connection string spec for more details.
  • opts.port {Number}: The MongoDB port, defaults to 27017. See the mongodb connection string spec for more details.
  • opts.database {String}: The MongoDB database, defaults to admin. See the mongodb connection string spec for more details.
  • opts.connectOptions {Object}: The MongoDB connection properties, being passed through to the native MongoDB driver. See mongoose' documentation, resp. MongoDB's native driver for node.js' documentation for more details.

Example

// Default Options:
const defaultOpts = {
   debug: false,
   host: 'localhost',
   port: 27017,
   database: '',
   connectOptions: {
     db: {},
     server: {
       auto_reconnect: true
     },
     replset: {},
     user: {},
     pass: {},
     auth: {},
     mongos: {}
   }
};

.constructor()

Initialize a new MongooseConnectionConfig.

Basic Example:

Params

  • {Configuration}: config - Configuration options overriding the default ones.

Example

const MongooseConnectionConfig = require('./src');

const opts = {
  host: process.env.MONGO_HOST || 'localhost',
  port: process.env.MONGO_PORT || 27017,
  database: 'my-db'
};
const mcc = new MongooseConnectionConfig(opts);

console.log(mcc.getMongoUri()); // => mongodb://localhost:27017/my-db   *

Example:

  • returns {Object}

Example

const MongooseConnectionConfig = require('./../src');

let mongooseConnectionConfig = new MongooseConnectionConfig();
console.log(mongooseConnectionConfig.DEFAULT_CONFIG);

Get the connection string.

  • returns {string}

Author

Stefan Walther

License

MIT


This file was generated by verb-generate-readme, v0.6.0, on June 01, 2019.