client
MongoClient configured mongo client to use. Can be null if url is setdatabaseName
string? name of the mongodb databasecollectionName
string name of the mongodb collection used to store the resourcesresourceName
string name of the resource e.g. users, customers, topics, shipments
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'
})
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}ref
Object 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<Objecft>)
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>