@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

Stats

StarsIssuesVersionUpdatedCreatedSize
@knetik/micro-mongoose
3.0.172 years ago4 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 app_id 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 })
}

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.