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, load
ing, and unload
ing 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}
forGLOBAL
,{topic, value}
forRESOURCE
) -
collectionName
String The name of the collection within the database. -
dbName
String The name of the DB to use. By default, thebits
DB is used. -
url
String The Mongo process URL to use. By default, the URL ismongodb://127.0.0.1
-
port
String The Mongo process port to use. By default, the port is27017
-
...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