client
MongoClient? configured mongo client to use. Can be null if url is setdatabaseName
string? name of the mongodb databasecollectionName
string name of the mongodb collection used to store the resourcesindexes
Array<Object>? indexes to be created on instantiation. Use format {key:1} for single indexes and {key1: 1, key:2} for compound indexes. See https://www.mongodb.com/docs/manual/reference/command/createIndexes/#command-fields
const { MongoClient } = require('mongodb')
const { SimpleResourceStorage } = require('@discue/mongodb-resource-client')
const client = new MongoClient(url, {
serverApi: { version: '1', strict: true, deprecationErrors: true }, // https://www.mongodb.com/docs/manual/reference/stable-api/
})
const storage = new SimpleResourceStorage({
client,
collectionName: 'api_clients',
})
Simple resource class with crud operation methods to create, update, delete, and get stored entities and documents.
Type: Function
Returns a resource by ids.
resourceIds
(String | Array<String>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}options
GetOptions
Returns Object
Returns all resources.
options
GetOptions
Returns all children of a certain type/collection. Imagine this method walking a tree and returning all leaves at a certain level.
Currently only supports trees with three levels.
resourceIds
(String | Array<String>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}childPath
(String | Array<String>) the path of the children to query e.g. /api_clients/queues/messagesoptions
GetChildrenOptions?
Returns Promise<ChildrenAndResourcePaths>
Returns all resources that pass the given aggregation stages.
Returns true if a resource with given ids exists.
Returns boolean
Adds a resource to a collection by ids.
resourceIds
(String | Array<String>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}resource
Object the resource to be stored
Updates a resource by ids.
resourceIds
(String | Array<String>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}update
Object values that should be updated
Deletes a resource by ids.
resourceIds
(String | Array<String>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}
Closes the database client
Returns void