npm.io
2.3.2 • Published 6 years ago

services-db-mixin

Licence
MIT
Version
2.3.2
Deps
3
Size
6 kB
Vulns
0
Weekly
0
Stars
2

Rancagua Digital Moleculer DB Mixin

Description

Moleculer Mixin to provide a MongoDB database interface to Moleculer microservices.

Installation

npm install services-db-mixin or yarn add services-db-mixin

Usage

When defining your Moleculer service add the DBService as a mixin:

const DBService = require('services-db-mixin')

module.exports = {
  name: '<service-name>',
  version: 1,

  mixins: [
    DbService(
      '<bd-url> or an empty string to use MONGO_URI env var',
      '<collection-name>',
      { version: 1, name: '<logging-service-name>', action: '<service-action-to-call>' }),
  ],
  ...
}

NOTE: If you don't pass a database url or don't set the MONGODB_URI env var, This package will use moleculer-db MemoryAdapter. This is usefull for running tests without hitting the database.

Keywords