@availjs/avail-mongo
v1.1.3
Published
avail services with mongo
Downloads
20
Readme
AvailMongo
Higher Order Mongo Avail Service that adds a mongoConnect
method to your Avail Service.
WithMongo is powered by the Mongodb core library
Installation
npm i @availjs/avail-bunyan
Usage
AvailMongo exposes a Higher Order Service function called WithMongo
.
WithMongo
takes a Mongo Connection String and
returns an Avail Constructor. By default WithMongo will use the Avail class as it's base class, but takes
a Base Class as it's second parameter.
const {Avail} = require('@availjs/avail');
const {WithMongo} = require('@availjs/avail-mongo');
class MyAvailService extends Avail {}
const connectionString = 'mongodb://192.168.1.1/db';
// pass in to the Constructor Factory
const MyAvailServiceConstructor = WithMongo(connectionString, MyAvailService);
const myAvailService = new MyAvailServiceConstructor('MyAvailService');
// or pass in the connectionString when calling mongoConnect()
myAvailService.mongoConnect(connectionString);
assert(typeof myAvailService.mongoConnect, 'function');
// or you can use the static helper OrchestrateWithMongo to connect to mongo as a
// part of the Avail init() function
const MyMongoServiceConstructor = WithMongo();
// @NOTE: that OrchestrateMongo does not fire the ON_CONNECT and ON_CONNECT_ERROR events
const myMongoService = MyMongoServiceConstructor.OrchestrateMongo(connectionString);