Moleculer Mixin to provide a MongoDB database interface to Moleculer microservices.
npm install services-db-mixin
or
yarn add services-db-mixin
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.