1.1.18 • Published 8 months ago

@bootloader/mongon v1.1.18

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

!! Mongo On !!

Multi-tenant wrapper for mongoose. Once DB models is created use mongoose documentation for further use Mongoose Documentation

Install

npm i @bootloader/mongon --save

Configure

in .env or config/local.properties

####### MONGODB ##############
## DB Credentials
mongodb.url = mongodb://<username>:<password>@<host>:27017/<db>?authSource=admin&authMechanism=SCRAM-SHA-1&maxPoolSize=20&retryWrites=false

## Prefix for DB eg:- tnt_ default is none, domain parameter will be used as it is for dbname
mongodb.db.prefix=

mongodb.debug=false

## ssl configuration
mongodb.secured.enabled=false
mongodb.secured.ssl=true
mongodb.secured.sslValidate=true

## Path to ssl certificate
mongodb.secured.sslCA=./rds-combined-ca-bundle.pem

Add Schema

Usually in your app/schema folder, you will have schema file sample_schema.js

const mongon = require('@bootloader/mongon');
module.exports = mongon.Schema({  
        //Message
        "type" : { type : String },
        "title" :{ type : String },
        "message" :{ type : String },
        //STAMPS
        "createdAt" : mongon.Schema.Types.Mixed,
        "readAt" : mongon.Schema.Types.Mixed,
        "active" :  Boolean,
},{ 
        minimize: false , collection: 'SAMPLE'
});

Use API

const mongon = require('@bootloader/mongon')
const SampleScheme = require('../schema/sample_schema');

module.exports = {
    async findAll(){
        let SampleModel = mongon.model(SampleScheme); // Get Model
        let doc = await SampleModel.find(); // Find Model with mongoose API's
        return doc;
    },
    async save({type,message}){  // Save to Default DB
        let SampleModel = mongon.model(SampleScheme,{}); 
        let doc = await SampleModel.save({
            type,message
        });
        return doc;
    },
    async saveToDifferent({type,message},tenant){  // Save to Another DB
        let SampleModel = mongon.model(SampleScheme,{
            domain : tenant
        });
        let doc = await SampleModel.save({
            type,message
        });
        return doc;
    }
}
1.1.1

1 year ago

1.1.0

1 year ago

1.1.9

10 months ago

1.1.8

10 months ago

1.1.7

11 months ago

1.1.6

11 months ago

1.1.5

11 months ago

1.1.4

11 months ago

1.1.3

12 months ago

1.1.2

12 months ago

1.1.12

9 months ago

1.1.11

9 months ago

1.1.10

10 months ago

1.1.16

8 months ago

1.1.15

8 months ago

1.1.14

8 months ago

1.1.13

9 months ago

1.1.18

8 months ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago