services-db-mixin
v2.3.2
Published
Moleculer mixin to provide a mongodb interface for microservices
Downloads
9
Maintainers
Readme
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.