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 { OneToFewResourceStorage } 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 oneToFewResourceStorage = new OneToFewResourceStorage({
client,
collectionName: 'api_clients',
resourceName: 'queues'
})withMetadataboolean true if also meta data should be returnedprojectionobject MongoDB projection object e.g. { id: 0, name: 0 }
Allows to manage a list of documents in another document to e.g. store a list of students of each school. As the child documents will be embedded, it is easy to retrieve them (only one query), but harder to get all students across e.g. a country in various schools.
Universities collection
{
name: 'University Munich',
students: [
{
name: 'Stef',
city: 'Munich
},
{
name: 'Frank',
city: 'Stuttgart
}
]
}Returns a resource by ids.
resourceIds(string | Array<string>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}optionsGetOptions
Returns all resources.
resourceIds(string | Array<string>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}optionsGetOptions
Returns Promise<Array<object>>
Add a resource to a collection by ids.
resourceIds(string | Array<string>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}resourceobject the resource to be stored
Returns string the id of the new object
Updates a resource by ids
resourceIds(string | Array<string>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}updateobject values that should be updated
Returns void
Deletes a resource by ids
resourceIds(string | Array<string>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}
Returns void