@availjs/avail-mongo

avail services with mongo

Stats

StarsIssuesVersionUpdatedCreatedSize
@availjs/avail-mongo
1.1.33 years ago3 years agoMinified + gzip package size for @availjs/avail-mongo in KB

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

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.