Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bimedia-fr/architect-mongodb-native
Expose a mongodb client as architect plugin.
https://github.com/bimedia-fr/architect-mongodb-native
Last synced: 2 months ago
JSON representation
Expose a mongodb client as architect plugin.
- Host: GitHub
- URL: https://github.com/bimedia-fr/architect-mongodb-native
- Owner: bimedia-fr
- License: apache-2.0
- Created: 2014-06-18T16:08:39.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-08-19T14:04:30.000Z (5 months ago)
- Last Synced: 2024-09-29T00:48:23.329Z (4 months ago)
- Language: JavaScript
- Size: 47.9 KB
- Stars: 1
- Watchers: 10
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
architect-mongodb-native
========================Expose a mongodb client as architect plugin.
### Installation
```sh
npm install --save architect-mongodb-native
```
### Config Format
```js
{
"packagePath": "architect-mongodb-native",
"url": "mongodb://127.0.0.1:27017/test"
}
```### Supported config elements
#### url
MongoDB server url.#### config
Additional mongodb [config parameters](http://mongodb.github.io/node-mongodb-native/api-generated/mongoclient.html#constructor).### Usage
Boot [Architect](https://github.com/c9/architect) :
```js
var path = require('path');
var architect = require("architect");var configPath = path.join(__dirname, "config.js");
var config = architect.loadConfig(configPath);architect.createApp(config, function (err, app) {
if (err) {
throw err;
}
console.log('application started');
});
```Configure mongodb with `config.js` :
```js
module.exports = [{
packagePath: "architect-mongodb-native",
url : 'mongodb://127.0.0.1:27017/test'
}, './routes'];
```Consume *mongo* service in your application :
```js
{
"name": "routes",
"version": "0.0.1",
"main": "index.js",
"private": true,"plugin": {
"consumes": ["mongo"]
}
}
```Eventually use the `mongo` service in your app :
```js
module.exports = function setup(options, imports, register) {
var db = imports.mongo.db;
db.collection('test').update({hi: 'here'}, {$set: {hi: 'there'}}, {w:1}, function(err) {
if (err) console.warn(err.message);
else console.log('successfully updated');
});
register();
};
```### Options
* url : mongoclient connect url
* config : additionnal connection parameter
* config.logger: ['error', 'info', 'debug'] enable mongodb driver logs with the selected level.### multiple connections
Multiple mongo connection are supported.
For instance :```js
module.exports = [{
packagePath: "architect-mongodb-native",
first:{
url : 'mongodb://127.0.0.1:27017/test'
},
second:{
url : 'mongodb://127.0.0.1:27017/other'
},
config: {
readPreference: 'secondaryPreferred',
replicaSet: 'myreplset'
}
}, './routes'];
```