DPDK Architecture  ->  Bootstrap (v3.0.5)

MongoDB
>= v1.4.3

MongoDB is already included in the bootstrap and can be used to communicate to a Mongo database.
By default MongoDB is disabled unless you add the connection details to your application config like this:

{
  "mongo": {
    "host": "localhost",
    "port": 27017,
    "username": "root",
    "password": "root",
    "database": "database_name"
  }
}

Models
>= v1.4.3

The creation of models is automated in the bootstrap.
Add your collection file to the app/collections folder in your project.
An example would be (Robot.json):

{
  "id": {
    "type": "Number",
    "description": "Unique identifier for the robot"
  },
  "name": {
    "type": "String",
    "description": "Name of the robot"
  },
  "active": {
    "type": "Boolean",
    "description": "Is the robot active"
  }
}

Additional Mongoose Schema Documentation: https://mongoosejs.com/docs/guide.html#definition

Manual Usage
>= v1.4.3

Models are available for manual usage:

const NextBootstrap = require('@dpdk/bootstrap');
const bootstrap = new NextBootstrap(__dirname, process.cwd(), nextConfig);

bootstrap.init();

const models = bootstrap.mongo.models;
models.Robot.find().then((data) => {
    console.log('data', data);
});

Indexes
>= v1.20.4

Simple indexes can be set in config like this (this will be used by GraphQL for sorts/filters):

{
  "mongo": {
    "index": {
    "page": [
        {
          "nid": 1
        },
        {
          "title": 1
        }
      ]
    }
  }
}

Replica Sets
>= v1.30.1

The mongo config can be extended to allow replica sets to work on a loadbalanced mongo setup:

{
  "mongo": {
    "replica": {
      "name": "replicaName",
      "hosts": [
        {
          "host": "mongo2.local",
          "port": 27017
        },
        {
          "host": "mongo3.local",
          "port": 27017
        }
      ]
    }
  }
}

Additional Mongoose Documentation: https://mongoosejs.com/docs/api.html

Additional MongoDB Documentation: https://docs.mongodb.com/manual/

Last modifiedFriday, April 30, 2021, 12:00:21 PM UTC
Last authorColin van Eenige
Commit ID4c7a701