@knetik/micro-mongoose

This package add the mongoose mongodb client to any [micro-core](https://www.npmjs.com/package/@knetik/micro-core) application as a multi tenant adaptor

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@knetik/micro-mongoose
3.0.174 years ago5 years agoMinified + gzip package size for @knetik/micro-mongoose in KB

Readme

Knetik Micro Mongoose
This package add the mongoose mongodb client to any micro-core application as a multi tenant adaptor
When a customer connects to a micro-core application, the required appid is passed into the mongoose initializer and used as the database name. Then creating a connection and loading any mongoose models defined in the models directory.
In app/models/example.mongoose.js
const mongoose = require('mongoose');

const ExampleSchema = new mongoose.Schema({
    'prop': { 'type': Number, 'required': true },
}, { 'strict': true });

module.exports = mongoose.model('Example', ExampleSchema);

In micro-console
App.connect(app_id, access_token)
.then(App => App.Mongoose.get('Exmaple'))
.then(Example => Example.create({ prop: 42 }))
.then(res => console.log(res))
.catch(err => console.log(err))

In a micro-core module
module.exports (App) => {
  cosnt Example = App.Mongoose.get('Exmaple')
  Example.create({ prop: 42 })
}