@lgslabs/bits-mongo-crud

MongoDB CRUD for BITS


Keywords
bits, bits-crud, mongo, mongodb
License
Apache-2.0
Install
npm install @lgslabs/bits-mongo-crud@4.0.1

Documentation

BITS MongoDB CRUD

The MongoDB-backed implementation of CRUD for BITS. This package extends the functionality provided in bits-memory-crud. All items in the collection are expected to be properly-formatted JSON objects. Mongo automatically adds an _id field in the form of its ObjectId. For documentation on using MongoDB's, queries and options, refer to the page about CRUD operations.

Use

Importing

npm install @lgslabs/bits-mongo-crud
const {MongoDbCrudService, MongoDbCrudManager, MongoDbCrudMessenger, MongoDbCrudApi, MongoDbCrudRouter} = require('@lgslabs/bits-mongo-crud');

Service

The Service is responsible for creating, loading, and unloading the manager, messenger, router (if desired), a public API (if desired), and any resources the subsystem may need.

load

Loads the Service, thereby creating and loading the other subsystem components with the provided options

load({messageCenter, tag, scopes, readScopes, writeScopes, filter, routePath, routerFilepath, apiExport, apiData, collectionName, dbName, url, port, ...args})
  • messageCenter MessageCenter The MessageCenter to use
  • tag String The tag to use for requests/events
  • scopes Array The scopes to use on requests/events
  • readScopes Array The scopes for read-type requests/events
  • writeScopes Array The scopes for write-type requests
  • filter Boolean True if the Messenger should filter CRUD events, false otherwise
  • routePath String The path to use for the router (optional)
  • routerFilepath String The path to the Router class to use (optional)
  • apiExport Symbol(API_EXPORT) How to export the API. This must be a value from API_EXPORT object in order to export
  • apiData Object The data to supply for export ({name, filepath} for GLOBAL, {topic, value} for RESOURCE)
  • collectionName String The name of the collection within the database.
  • dbName String The name of the DB to use. By default, the bits DB is used.
  • url String The Mongo process URL to use. By default, the URL is mongodb://127.0.0.1
  • port String The Mongo process port to use. By default, the port is 27017
  • ...args Any number of additional key/value pairs
  • Returns Promise resolving to request or rejecting to error

createManager

Called in the Service's load function to create the manager. By default, it creates an instance of the base implementation of the MongoDB CRUD manager. If the subsystem needs additional functionality, it is recommended to override this function.

createManager()
  • Returns Promise resolving to request or rejecting to error