clientMongoClient configured mongo client to use. Can be null if url is setdatabaseNamestring? name of the mongodb databasecollectionNamestring name of the mongodb collection used to store the resourcesindexesArray<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
import { MongoClient } from 'mongodb'
import { SimpleResourceStorage } from '@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}optionsGetOptions
Returns object
Returns all resources.
optionsGetOptions
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/messagesoptionsGetChildrenOptions?
Returns Promise<ChildrenAndResourcePaths>
Returns the count of all children of a certain type/collection.
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/messagesoptionsGetChildrenOptions?
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}resourceobject the resource to be stored
Adds a resource to a collection without any checks.
resourceIds(string | Array<string>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}resourceobject the resource to be stored
Returns any
Updates a resource by ids.
resourceIds(string | Array<string>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}updateobject values that should be updatedoptionsUpdateOptions
Deletes a resource by ids.