Giter VIP home page Giter VIP logo

dc-api-mongo's Introduction

Mongoose based MongoDB driver for dc-api-core

NPM

Provides mongo database driver and session store.

Dependencies


Installation

  1. Install package - npm i dc-api-mongo --save or yarn add dc-api-mongo
  2. Add dc-api-mongo to plugins array in config.json
  3. Fill db field in config.json by template
  4. Create directory models in back-end root
  5. Create directory mongo in models
  6. Done!

config.json template

Field Default Description
db.mongo.uri Autogenerated MongoDB URI
db.mongo.host Required Database hostname
db.mongo.name Required Database name
db.mongo.port 27017 Database port
db.mongo.user Optional Database username
db.mongo.pass and password
db.mongo.nonStrict [] List of models without schema
db.mongo.srv false If true using SRV record
db.mongo.* Optional Query parameters in URI

Example configuration

{
    "db": {
        "mongo.billing": {
            "uri": " mongodb+srv://admin:[email protected]/billing?authSource=admin&retryWrites=true&w=majority"
        },
        "mongo.control-panel"
            "host": "project-00000.provider.mongodb.net",
            "user": "admin",
            "pass": "password",
            "name": "control-panel",
            "srv": true,
            "authSource": "admin",
            "retryWrites": true,
            "w": "majority"
        }
    }
}

Creating model

  1. Create file ModelName.js in models/mongo directory
  2. Fill model file.
  3. Done!

Example:

module.exports = {
    // Any mongoose schema constuctions allowed
    field: { type: String, required: true },
    otherField: { type: Number, default: Date.now() + 1000 * 60 },

    // Second argument of schema constuctor
    // new Schema(..., $options)
    $options: { strict: false },

    // Register default auto-increment field "uid"
    $increment: 'uid',
    // Same with options
    $increment: { field: 'uid', start: 1 },

    // Mongoose virtual fields
    $virtuals: {
        timestamp: {
            // schema.virtual('timestamp').get(<this function>)
            get () {
                // `document.timestamp` will return creation time in ms
                return this._id.getTimestamp().getTime();
            }
        }
    }
};

Other examples you can find in Mongoose Docs.

dc-api-mongo's People

Contributors

dimacrafter avatar mayerdev avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dc-api-mongo's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.