# mongoconfig

> Store your application configuration in MongoDB

Latest version **1.1.0** (published 2016-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install mongoconfig
pnpm add mongoconfig
yarn add mongoconfig
bun add mongoconfig
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2016-09-07 |
| First published | 2014-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+10 in 2 direct dependencies) |
| Install scripts | no |
| Author | Linagora Folks |
| Maintainers | linagora |
| Keywords | mongodb, mongoose, configuration, storage |

## Links

- npm: https://www.npmjs.com/package/mongoconfig
- Repository: http://ci-openpaas.linagora.com/stash/scm/or/mongoconfig
- npm.io page: https://npm.io/package/mongoconfig

## Dependencies (2)

- [dotty](https://npm.io/package/dotty.md) 0.0.2
- [mongoose](https://npm.io/package/mongoose.md) 4.6.0

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2016-09-07
- 1.0.0 — 2014-03-05

## README

MongoConfig
===========

MongoConfig is a tiny library to store and get configuration documents from MongoDB. It uses the mongoose driver.

Quick usage
-----------

### Storing a configuration document in MongoDB

    var mongoConfig = require('mongoconfig');
    var mongoose = require('mongoose');
    mongoose.connect('mongodb://myserver:27017/mydb');
    
    var config = {
      'hostname': 'smtp.example.com',
      'port': 25,
      'tls': true
    };
    
    // store config in the 'configuration' collection,
    // the document _id will be 'smtp'
    mongoConfig('smtp').store(config, function(err) {
      if ( !err ) {
        console.log('Configuration stored');
      }
    });

### Updating a configuration document

    var mongoConfig = require('mongoconfig');
    var mongoose = require('mongoose');
    mongoose.connect('mongodb://myserver:27017/mydb');
        
    // add the "antispam" key in the 'smtp' configuration document 
    // of the 'configuration' collection
    mongoConfig('smtp').set('antispam', true, function(err) {
      if ( !err ) {
        console.log('Configuration updated');
      }
    });

    
    // also supports the dot notation
    mongoConfig('smtp').set('options.antivirus', true, function(err) {
      if ( !err ) {
        console.log('Configuration updated');
      }
    });

### Getting a complete configuration document

    // get config from the 'configuration' collection,
    mongoConfig('smtp').get(function(err, cfg) {
      if ( !err ) {
        console.log('Got configuration: ', cfg);
      }
    });

### Getting a specific key from a configuration document

    // get the content of the "hostname" key
    mongoConfig('smtp').get('hostname', function(err, cfg) {
      if ( !err ) {
        console.log('Configuration stored');
      }
    });
    
    // also support dot notation
    mongoConfig('smtp').get('options.antivirus', function(err, cfg) {
      if ( !err ) {
        console.log('options.antivirus', cfg);
      }
    });

Detailed Usage
--------------

The MongoConfig module only needs one argument: the namespace of the ocnfiguration document

    var mongoConfig = require('mongoconfig')('smtp');
    
The second argument, if set, is the MongoDB collection name where documents will be stored/fetched. The default collection name is 'configuration'.

    var mongoConfig = require('mongoconfig')('smtp', 'myConfigurationCollection');

The third argument is an option hash. For now it only supports one key: 'mongoose', that gives the mongoose instance to use. If it's not set, mongoConfig uses "require('mongoose')" to get mongoose.

    var mongoConfig = require('mongoconfig')('smtp', null, {mongoose: myMongoose});

You can configure the module, to set the default collection name:

    var mongoConfig = require('mongoconfig');
    mongoConfig.setDefaultCollectionName('myOwnCollectionName');

You can configure the module, to set the default mongoose instance:

    var mongoConfig = require('mongoconfig');
    mongoConfig.setDefaultMongoose(myMongoose);

Tests
-----

Use the command:

    grunt

to launch the test suite. For it to work, you'll need gjslint, and a Mongodb server listening on localhost:27017.

Licence
-------

GNU GPLv3

Others
------

This was coded with love by [Linagora](http://linagora.com).

Use, share, fork, send pull requests !

---
_Source: https://npm.io/package/mongoconfig · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
