MongoDB
Collection of MongoDB functions.
Methods
aggregate
aggregate(connectionString: string, database: string, collection: string, query: { [key: string]: any; }, options?: { [key: string]: any; })
Equivalent to the MongoDB aggregate function. See this documentation for usage
Parameters
connectionString string
The connection string to the MongoDB database.
database string
The name of the database.
collection string
The name of the collection.
query { [key: string]: any; }
A sequence of data aggregation operations or stages. See the MongoDB aggregation pipeline operators for details.
options { [key: string]: any; }
(optional) 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
bulkWrite(connectionString: string, database: string, collection: string, operations: { [key: string]: any; }, writeConcern?: { [key: string]: any; }, ordered?: boolean)
Performs multiple write operations with controls for order of execution. Equivalent to the MongoDB BulkWrite function. See this documentation for usage
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; }
A sequence of BulkWrite write operations. See MongoDB write operations for details.
writeConcern { [key: string]: any; }
(optional) A document expressing the write concern. Omit to use the default write concern. See MongoDB bulkWrite for details.
ordered boolean
(optional) A boolean specifying whether the mongodb instance should perform an ordered or unordered operation execution. Defaults to true.
Return type
{ [key: string]: any; }
Examples
findOne
findOne(connectionString: string, database: string, collection: string, query: { [key: string]: any; }, options?: { [key: string]: any; })
Find and return the first document that matches the query. Equivalent to the MongoDB findOne function. See this documentation for usage
Parameters
connectionString string
The connection string to the MongoDB database.
database string
The name of the database.
collection string
The name of the collection.
query { [key: string]: any; }
Specifies query selection criteria using query operators.
options { [key: string]: any; }
(optional) Specifies 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
find
find(connectionString: string, database: string, collection: string, query: { [key: string]: any; }, options?: { [key: string]: any; })
Find and return multiple documents that match the query. Equivalent to the MongoDB find function. See this documentation for usage
Parameters
connectionString string
The connection string to the MongoDB database.
database string
The name of the database.
collection string
The name of the collection.
query { [key: string]: any; }
Specifies query selection criteria using query operators.
options { [key: string]: any; }
(optional) Specifies 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
insert
insert(connectionString: string, database: string, collection: string, document: { [key: string]: any; }, options?: { [key: string]: any; })
Insert one document. Equivalent to the MongoDB insertOne function. See this documentation for usage
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; }
Specifies the document to insert.
options { [key: string]: any; }
(optional) Specifies additional options for the insert statement. To see available options, see InsertOneOptions documentation.
Return type
{ [key: string]: any; }
Examples
insertMany
insertMany(connectionString: string, database: string, collection: string, documents: { [key: string]: any; }[], options?: { [key: string]: any; })
Insert one or more documents. Equivalent to the MongoDB insertMany function. See this documentation for usage
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; }[]
Specifies the documents to insert.
options { [key: string]: any; }
(optional) Specifies additional options for the insert statement. To see available options, see BulkWriteOptions documentation.
Return type
{ [key: string]: any; }
Examples
delete
delete(connectionString: string, database: string, collection: string, filter: { [key: string]: any; }, options?: { [key: string]: any; })
Delete the first document that matches the given filter. Equivalent to the MongoDB deleteOne function. See this documentation for usage
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) Specifies additional options for the delete statement. To see available options, see DeleteOptions documentation.
Return type
{ [key: string]: any; }
Examples
deleteMany
deleteMany(connectionString: string, database: string, collection: string, filter: { [key: string]: any; }, options?: { [key: string]: any; })
Delete all documents that matches the given filter. Equivalent to the MongoDB deleteMany function. See this documentation for usage
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) Specifies additional options for the delete statement. To see available options, see DeleteOptions documentation.
Return type
{ [key: string]: any; }
Examples
update
update(connectionString: string, database: string, collection: string, filter: { [key: string]: any; }, update?: { [key: string]: any; })
Update the first document that matches the filter. Equivalent to the MongoDB updateOne function. See this documentation for usage
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.
Return type
{ [key: string]: any; }
Examples
updateMany
updateMany(connectionString: string, database: string, collection: string, filter: { [key: string]: any; }, update?: { [key: string]: any; })
Update all documents that matches the filter. Equivalent to the MongoDB updateMany function. See this documentation for usage
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.
Return type
{ [key: string]: any; }
Examples
Last updated