Skip to content

RancaguaInnova/services-db-mixin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.