Skip to content

Latest commit

 

History

History
162 lines (92 loc) · 4.89 KB

File metadata and controls

162 lines (92 loc) · 4.89 KB

ConstructorOptions

Properties

Examples

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',
})

SimpleResourceStorage

Simple resource class with crud operation methods to create, update, delete, and get stored entities and documents.

WithSessionCallback

Type: Function

get

Returns a resource by ids.

Parameters

  • resourceIds (string | Array<string>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}
  • options GetOptions

Returns object

getAll

Returns all resources.

Parameters

  • options GetOptions

Returns Array<object>

getAll

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.

Parameters

  • 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/messages
  • options GetChildrenOptions?

Returns Promise<ChildrenAndResourcePaths>

countAllChildren

Returns the count of all children of a certain type/collection.

Currently only supports trees with three levels.

Parameters

  • 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/messages
  • options GetChildrenOptions?

Returns Promise<number>

find

Returns all resources that pass the given aggregation stages.

Parameters

  • aggregations Array<object> a list of valid aggregation objects (optional, default [])

Returns Array<object>

exists

Returns true if a resource with given ids exists.

Parameters

Returns boolean

create

Adds a resource to a collection by ids.

Parameters

  • 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

create

Adds a resource to a collection without any checks.

Parameters

  • 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

Returns any

update

Updates a resource by ids.

Parameters

  • 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
  • options UpdateOptions

delete

Deletes a resource by ids.

Parameters

  • resourceIds (string | Array<string>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}