Kvell.js

Kvell.js

  • Docs
  • Database Plugins
  • Github

›Kvell Database Plugins

Kvell Database Plugins

  • Overview
  • kvell-db-plugin-sequelize
  • kvell-db-plugin-mongoose
Edit

Mongoose Plugin for kvell

Kvell-db-plugin-mongoose wraps up mongoose and exposes all three values required to be exposed by a kvell database plugin.

Install

npm i kvell-db-plugin-mongoose

Configuration Variables

Internally, kvell-db-plugin-mongoose will instantiate the database object using mongoose.connect method.

Documentation for mongoose

Usage

Example:

  • kvell-plugins.js:
module.exports = {
  databasePlugins: [
    {
      resolve: "kvell-db-plugin-mongoose",
      options: {
        mongoConnectionString: "mongodb://localhost:27017/test",
        options: {},
        showConnectionMessage: false
      }
    }
  ]
};
  • userModel.js:
const mongoose = require("kvell-db-plugin-mongoose").dbLib;

// Create your User model's schema here and export it.

const userSchema = new mongoose.Schema({
  name: String,
  email: String,
  password: String,
  age: Number
});

const User = mongoose.model("User", userSchema);

module.exports = User;

To use it, install the package and add a databasePlugin object in kvell-plugins.js with the following fields:

  • resolve: Name of the plugin, i.e, kvell-db-plugin-mongoose

  • options: All the parameters that you need to pass in the mongoose constructor. The following key is mandatory:

    • mongoConnectionString (string): The connection string for the mongoose server.

    You can add more keys which conform to the mongoose.connect api's options object. You can read more on that here.

  • showConnectionMessage (boolean): If set to true, a success message will be logged on the console once the connection is successfully established.

By default, the following options are taken as true while instantiating the mongoose instance:

  • useNewUrlParser
  • useUnifiedTopology

You may choose to override it by simply adding these keys as fields in the options field of the object.

The plugin exports the following:

  • dbLib: The mongoose object. Check mongoose docs for complete api reference.

  • dbInstance: The instantiated mongoose instance.

  • initHandler: (not for use)

Last updated on 7/16/2020 by Neeraj Sharma
← kvell-db-plugin-sequelize
  • Install
  • Configuration Variables
  • Usage
Kvell.js
Docs
Getting StartedGuidesDatabase Plugins
Social
kvell
Follow @nsharma1396
Copyright © 2020 Neeraj Sharma.