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 { OneToFewResourceStorage } = 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 oneToFewResourceStorage = new OneToFewResourceStorage({
client,
collectionName: 'api_clients',
resourceName: 'queues'
})
withMetadata
boolean true if also meta data should be returnedprojection
Object 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}options
GetOptions
Returns all resources.
resourceIds
(String | Array<String>) resource ids that will added to the resource path i.e. /users/${id}/documents/${id}options
GetOptions
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}resource
Object the resource to be stored
Returns ObjectId
Updates a resource by ids
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
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