1.1.3 • Published 6 years ago

@availjs/avail-mongo v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

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);
  
1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago