1.0.6 • Published 4 years ago

mongobase v1.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Mongobase

Overview

A lightweight starter template based off the native mongodb driver. Comes with basic CRUD operations and middleware support.

Getting started

Installation

npm install mongobase

or

yarn add mongobase

Basic Usage

const mongobase = require('mongobase')

mongobase.init(url, database, options)
mongobase.start()
    .then(() => {
        class UsersModel extends mongobase.Model {
        }
        const collectionName = 'Users'

        const Collection = mongobase.create(collectionName, UsersModel)

        const newUser = { hello: 'world' }

        Colllection.create(newUser)
            .then(doc => {
                console.log(doc)
                //{ hello: 'world', _id: 5e60b3d317e6c15153f0476f }
            })
    })

Advanced Usage

Usage with your own mongo database setup

const { MongoClient } = require('mongodb')
const { Model, collection } = require('mongobase')

const collectionName = 'users'
class CustomModel extends Model {
}

const { url, options, db } = configuration
MongoClient.connect(url, options, (err, client) => {
    if(err) return reject(err)

    const database = client.db(db)
    const Collection = collection(collectionName, CustomModel, database)

    const newDocument = { hello: 'fizz', world: 'buzz' }

    Collection
        .create(newDocument)
        .then(doc => {
            console.log(doc)
            //{ hello: 'fizz', world: 'buzz', _id: 5e60b3d317e6c15153f0476f }
        })

})
1.0.2

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago