Code Monkey home page Code Monkey logo

hapi-mongo-models's Introduction

hapi-mongo-models

A hapi plugin for mongo-models.

Build Status Dependency Status devDependency Status peerDependency Status

Install

$ npm install hapi-mongo-models

Server plugin

During plugin registration we connect to MongoDB using the supplied options.

During Hapi's onPreStart server extension point and based on your autoIndex option, we create any indexes defined in the models supplied.

Register

const HapiMongoModels = require('hapi-mongo-models');

const plugin = {
    plugin: HapiMongoModels,
    options: {
        mongodb: {
            connection: {
                uri: 'mongodb://localhost:27017/',
                db: 'hapi-mongo-models-test'
            },
            options: {}
        },
        models: [
            './path/to/customer',
            './path/to/order'
        ],
        autoIndex: false
    }
};

await server.register(plugin);

Plugin options

The options passed to the plugin is an object where:

  • mongodb - is an object where:
    • connection - is an object where:
      • uri - a string representing the connection uri for MongoDB.
      • db - the name of the database.
    • options - an optional object passed to MongoDB's native connect function.
  • autoIndex - a boolean specifying if the plugin should call createIndexes for each model that has a static indexes property. Defaults to true. Typically set to false in production environments.
  • models - an array strings representing the paths to the models (relative to the current working directory or absolute) of where to find the model on disk.

Have a question?

Any issues or questions (no matter how basic), open an issue. Please take the initiative to read relevant documentation and be pro-active with debugging.

Want to contribute?

Contributions are welcome. If you're changing something non-trivial, you may want to submit an issue before creating a large pull request.

Note: This plugin is designed for basic use-cases. If you find yourself needing more, consider using the source as inspiration and create a custom plugin for your app.

License

MIT

Don't forget

What you create with hapi-mongo-models is more important than hapi-mongo-models.

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.