Service
Service API reference
find
Fetches documents that matches the filter. Returns an object with the following fields(FindResult
):
Field | Description |
---|---|
results | documents, that matches the filter |
count | total number of documents, that matches the filter |
pagesCount | total number of documents, that matches the filter divided by the number of documents per page |
Pass page
and perPage
params to get a paginated result. Otherwise, all documents will be returned.
Parameters
- filter:
Filter<U>
; - readConfig:
ReadConfig
& { page?: number; perPage?: number }
; - findOptions:
FindOptions
;
Returns Promise<FindResult<U>>
.
findOne
Fetches the first document that matches the filter. Returns null
if document was not found.
Parameters
- filter:
Filter<U>
; - readConfig:
ReadConfig
; - findOptions:
FindOptions
;
Returns Promise<U | null>
.
updateOne
Updates a single document and returns it. Returns null
if document was not found.
Parameters
- filter:
Filter<U>
; - updateFn:
(doc: U) => Partial<U>
;
Function that accepts current document and returns object containing fields to update. - updateConfig:
UpdateConfig
; - updateOptions:
UpdateOptions
;
Returns Promise<U | null>
.
updateMany
Updates multiple documents that match the query. Returns array with updated documents.
Parameters
- filter:
Filter<U>
; - updateFn:
(doc: U) => Partial<U>
;
Function that accepts current document and returns object containing fields to update. - updateConfig:
UpdateConfig
; - updateOptions:
UpdateOptions
;
Returns Promise<U[]>
.
insertOne
Inserts a single document into a collection and returns it.
Parameters
- object:
Partial<U>
; - createConfig:
CreateConfig
; - insertOneOptions:
InsertOneOptions
;
Returns Promise<U>
.
insertMany
Inserts multiple documents into a collection and returns them.
Parameters
- objects:
Partial<U>[]
; - createConfig:
CreateConfig
; - bulkWriteOptions:
BulkWriteOptions
;
Returns Promise<U[]>
.
deleteSoft
Adds deletedOn
field to the documents that match the query and returns them.
Parameters
- filter:
Filter<U>
; - deleteConfig:
DeleteConfig
; - deleteOptions:
DeleteOptions
;
Returns Promise<U[]>
.
deleteOne
Deletes a single document and returns it. Returns null
if document was not found.
Parameters
- filter:
Filter<U>
; - deleteConfig:
DeleteConfig
; - deleteOptions:
DeleteOptions
;
Returns Promise<U | null>
.
deleteMany
Deletes multiple documents that match the query. Returns array with deleted documents.
Parameters
- filter:
Filter<U>
; - deleteConfig:
DeleteConfig
; - deleteOptions:
DeleteOptions
;
Returns Promise<U[]>
.
replaceOne
Replaces a single document within the collection based on the filter. Doesn’t validate schema or publish events.
Parameters
- filter:
Filter<T>
; - replacement:
Partial<T>
; - readConfig:
ReadConfig
; - replaceOptions:
ReplaceOptions
;
Returns Promise<
UpdateResult |
Document>
.
atomic.updateOne
Updates a single document. Doesn’t validate schema or publish events.
Parameters
- filter:
Filter<T>
; - updateFilter:
UpdateFilter<T>
; - readConfig:
ReadConfig
; - updateOptions:
UpdateOptions
;
Returns Promise<
UpdateResult>
.
atomic.updateMany
Updates all documents that match the specified filter. Doesn’t validate schema or publish events.
Parameters
- filter:
Filter<T>
; - updateFilter:
UpdateFilter<T>
; - readConfig:
ReadConfig
; - updateOptions:
UpdateOptions
;
Returns Promise<
UpdateResult |
Document>
.
exists
Returns true if document exists, otherwise false.
Parameters
- filter:
Filter<T>
; - readConfig:
ReadConfig
; - findOptions:
FindOptions
;
Returns Promise<boolean>
.
countDocuments
Returns amount of documents that matches the query.
Parameters
- filter:
Filter<T>
; - readConfig:
ReadConfig
; - countDocumentOptions:
CountDocumentsOptions
;
Returns Promise<number>
.
distinct
Returns distinct values for a specified field across a single collection or view and returns the results in an array.
Parameters
- key:
string
; - filter:
Filter<T>
; - readConfig:
ReadConfig
; - distinctOptions:
DistinctOptions
;
Returns Promise<any[]>
.
aggregate
Executes an aggregation framework pipeline and returns array with aggregation result of documents.
Parameters
- pipeline:
any[]
; - options:
AggregateOptions
;
Returns Promise<any[]>
.
watch
Creates a new Change Stream, watching for new changes and returns a cursor.
Parameters
- pipeline:
Document[] | undefined
; - options:
ChangeStreamOptions
;
Returns Promise<any>
.
drop
Removes a collection from the database. The method also removes any indexes associated with the dropped collection.
Parameters
- recreate:
boolean
; Should create collection after deletion.
Returns Promise<void>
.
indexExists
Checks if one or more indexes exist on the collection, fails on first non-existing index.
Parameters
- indexes:
string | string[]
; - indexInformationOptions:
IndexInformationOptions
;
Returns Promise<string | void>
.
createIndex
Creates collection index.
Parameters
- indexSpec:
IndexSpecification
; - options:
CreateIndexesOptions
;
Returns Promise<string | void>
.
createIndexes
Creates one or more indexes on a collection.
Parameters
- indexSpecs:
IndexDescription[]
; - options:
CreateIndexesOptions
;
Returns Promise<string[] | void>
.
dropIndex
Removes the specified index from a collection.
Parameters
- indexName:
string
; - options:
DropIndexesOptions
;
Returns Promise<void | Document>
.
dropIndexes
Removes all but the _id
index from a collection.
Parameters
- options:
DropIndexesOptions
;
Returns Promise<void | Document>
.