Skip to content

Latest commit

 

History

History
108 lines (67 loc) · 2.97 KB

README_ONE_TO_FEW_REF_STORAGE.md

File metadata and controls

108 lines (67 loc) · 2.97 KB

ConstructorOptions

Properties

  • client MongoClient configured mongo client to use. Can be null if url is set
  • databaseName string? name of the mongodb database
  • collectionName string name of the mongodb collection used to store the resources
  • resourceName string name of the resource e.g. users, customers, topics, shipments

Examples

const { MongoClient } = require('mongodb')
const { OneToFewRefstorage } = 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 oneToFewRefStorage = new OneToFewRefStorage({
  client,
  collectionName: 'api_clients',
  resourceName: 'queues'
})

OneToFewRefStorage

Similar to @link OneToFewResourceStorage, but allows only managing of references. Meaning: Instead of embedding objects in the target array this class only stores references to other objects.

Universities collection

{
  name: 'University Munich',
  students: [1828391, 9440201, 29930302]
}
{
  name: 'University Stuttgart',
  students: [551234, 115235, 4451515]
}

exists

Returns true if a resource with given ids exists.

Parameters

Returns boolean

getAll

Returns all references.

Parameters

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

Returns Array<Object>

create

Add a reference 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}
  • ref Object the resource to be stored

Returns Promise<ObjectId>

find

Delete a reference

Parameters

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

Returns Promise<void>

delete

Delete a reference

Parameters

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

Returns Promise<void>