Skip to content

Latest commit

 

History

History
140 lines (79 loc) · 4.04 KB

README_SIMPLE_RESOURCE_STORAGE.md

File metadata and controls

140 lines (79 loc) · 4.04 KB

ConstructorOptions

Properties

Examples

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

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>

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

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

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}

close

Closes the database client

Returns void