MongoDB

Collection of MongoDB functions.

Methods

aggregate

aggregate(connectionString: string, database: string, collection: string, pipeline: { [key: string]: any; }[], options?: { [key: string]: any; })

Equivalent to the MongoDB aggregate function. More informationarrow-up-right.

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

pipeline { [key: string]: any; }[]

An array of aggregation pipelines to execute. See the MongoDB aggregation pipeline operators for details.

options { [key: string]: any; }

(optional) The additional options that aggregate() passes to the MongoDB aggregate command. Available only if you specify the pipeline as an array.

Return type

{ [key: string]: any; }

Examples

bulkWrite

Performs multiple write operations with controls for order of execution. Equivalent to the MongoDB BulkWrite function. More informationarrow-up-right.

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

operations { [key: string]: any; }[]

The sequence of BulkWrite write operations. See MongoDB write operations for details.

options { [key: string]: any; }

(optional) The additional options that bulkWrite() passes to the MongoDB bulkWrite command. See the official MongoDB NodeJs documentation for the exact usage of these options. More informationarrow-up-right.

Return type

{ [key: string]: any; }

Examples

deleteMany

Delete all documents that matches the given filter. Equivalent to the MongoDB deleteMany function. More informationarrow-up-right.

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

filter { [key: string]: any; }

The filter used to select the documents to remove.

options { [key: string]: any; }

(optional) The additional options for the delete statement. To see available options, see DeleteOptions documentation.

Return type

{ [key: string]: any; }

Examples

delete

Delete the first document that matches the given filter. Equivalent to the MongoDB deleteOne function. More informationarrow-up-right.

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

filter { [key: string]: any; }

The filter used to select the document to remove.

options { [key: string]: any; }

(optional) The additional options for the delete statement. To see available options, see DeleteOptions documentation.

Return type

{ [key: string]: any; }

Examples

find

Find and return multiple documents that match the query. Equivalent to the MongoDB find function. More informationarrow-up-right.

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

filter { [key: string]: any; }

The filter predicate. If unspecified, then all documents in the collection will match the predicate.

options { [key: string]: any; }

(optional) The additional options for the query. These options modify query behavior and how results are returned. To see available options, see FindOptions documentation.

Return type

{ [key: string]: any; }[]

Examples

findOne

Find and return the first document that matches the query. Equivalent to the MongoDB findOne function. More informationarrow-up-right.

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

filter { [key: string]: any; }

The query for the find operation.

options { [key: string]: any; }

(optional) The additional options for the query. These options modify query behavior and how results are returned. To see available options, see FindOptions documentation.

Return type

{ [key: string]: any; }

Examples

insertMany

Insert one or more documents. Equivalent to the MongoDB insertMany function. More informationarrow-up-right.

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

documents { [key: string]: any; }[]

The documents to insert.

options { [key: string]: any; }

(optional) The additional options for the insert statement. To see available options, see BulkWriteOptions documentation.

Return type

{ [key: string]: any; }

Examples

insert

Insert one document. Equivalent to the MongoDB insertOne function. More informationarrow-up-right.

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

document { [key: string]: any; }

The document to insert.

options { [key: string]: any; }

(optional) The additional options for the insert statement. To see available options, see InsertOneOptions documentation.

Return type

{ [key: string]: any; }

Examples

updateMany

Update all documents that matches the filter. Equivalent to the MongoDB updateMany function. More informationarrow-up-right.

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

filter { [key: string]: any; }

The filter used to select the documents to update.

update { [key: string]: any; }

(optional) The update operations to be applied to the documents.

options { [key: string]: any; }

(optional) The additional options for the update statement. To see available options, see UpdateOptions documentation.

Return type

{ [key: string]: any; }

Examples

update

Update the first document that matches the filter. Equivalent to the MongoDB updateOne function. More informationarrow-up-right.

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

filter { [key: string]: any; }

The filter used to select the document to update.

update { [key: string]: any; }

(optional) The update operations to be applied to the document.

options { [key: string]: any; }

(optional) The additional options for the update statement. To see available options, see UpdateOptions documentation.

Return type

{ [key: string]: any; }

Examples

countDocuments

Count documents that matches the query. Equivalent to the MongoDB countDocuments function. More informationarrow-up-right.

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

filter { [key: string]: any; }

The query for the find operation.

options { [key: string]: any; }

(optional) The additional options for the query. These options modify query behavior. To see available options, see Count documents documentation.

Return type

number

Examples

Last updated