Skip to main content

find

Fetches documents that matches the filter. Returns an object with the following fields(FindResult): Pass page and perPage params to get a paginated result. Otherwise, all documents will be returned. Parameters Returns Promise<FindResult<U>>.

findOne

Fetches the first document that matches the filter. Returns null if document was not found. Parameters Returns Promise<U | null>.

updateOne

Updates a single document and returns it. Returns null if document was not found. Parameters Returns Promise<U | null>.

updateMany

Updates multiple documents that match the query. Returns array with updated documents. Parameters Returns Promise<U[]>.

insertOne

Inserts a single document into a collection and returns it. Parameters Returns Promise<U>.

insertMany

Inserts multiple documents into a collection and returns them. Parameters Returns Promise<U[]>.

deleteSoft

Adds deletedOn field to the documents that match the query and returns them. Parameters Returns Promise<U[]>.

deleteOne

Deletes a single document and returns it. Returns null if document was not found. Parameters Returns Promise<U | null>.

deleteMany

Deletes multiple documents that match the query. Returns array with deleted documents. Parameters Returns Promise<U[]>.

replaceOne

Replaces a single document within the collection based on the filter. Doesn’t validate schema or publish events. Parameters Returns Promise<UpdateResult | Document>.

atomic.updateOne

Updates a single document. Doesn’t validate schema or publish events. Parameters Returns Promise<UpdateResult>.

atomic.updateMany

Updates all documents that match the specified filter. Doesn’t validate schema or publish events. Parameters Returns Promise<UpdateResult | Document>.

exists

Returns true if document exists, otherwise false. Parameters Returns Promise<boolean>.

countDocuments

Returns amount of documents that matches the query. Parameters 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 Returns Promise<any[]>.

aggregate

Executes an aggregation framework pipeline and returns array with aggregation result of documents. Parameters Returns Promise<any[]>.

watch

Creates a new Change Stream, watching for new changes and returns a cursor. Parameters 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 Returns Promise<string | void>.

createIndex

Creates collection index. Parameters Returns Promise<string | void>.

createIndexes

Creates one or more indexes on a collection. Parameters Returns Promise<string[] | void>.

dropIndex

Removes the specified index from a collection. Parameters Returns Promise<void | Document>.

dropIndexes

Removes all but the _id index from a collection.
Parameters Returns Promise<void | Document>.