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 resourcesresourceNamestring name of the resource e.g. users, customers, topics, shipments
import { MongoClient } from 'mongodb'
import { OneToFewRefstorage } 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 oneToFewRefStorage = new OneToFewRefStorage({
client,
collectionName: 'api_clients',
resourceName: 'queues'
})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]
}Returns true if a resource with given ids exists.
Returns boolean
Returns all references.
resourceIds(string | Array<string>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}
Add a reference to a collection by ids.
resourceIds(string | Array<string>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}refobject the resource to be stored
Returns Promise<ObjectId>
Delete a reference
resourceIds(string | Array<string>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}references(string | Array<object>)
Returns Promise<void>
Delete a reference
resourceIds(string | Array<string>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}
Returns Promise<void>