Create a new Collection instance
The name of this collection
The name of the database this collection belongs to
The namespace of this collection, in the format ${this.dbName}.${this.collectionName}
The current readConcern of the collection. If not explicitly defined for this collection, will be inherited from the parent DB
The current readPreference of the collection. If not explicitly defined for this collection, will be inherited from the parent DB
The current writeConcern of the collection. If not explicitly defined for this collection, will be inherited from the parent DB
Execute an aggregation framework pipeline against the collection, needs MongoDB >= 2.2
An array of aggregation pipelines to execute
Optional settings for the command
Perform a bulkWrite operation without a fluent API
Legal operation types are
{ insertOne: { document: { a: 1 } } }
{ updateOne: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } }
{ updateMany: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } }
{ updateMany: { filter: {}, update: {$set: {"a.$[i].x": 5}}, arrayFilters: [{ "i.x": 5 }]} }
{ deleteOne: { filter: {c:1} } }
{ deleteMany: { filter: {c:1} } }
{ replaceOne: { filter: {c:3}, replacement: {c:4}, upsert:true} }
Please note that raw operations are no longer accepted as of driver version 4.0.
If documents passed in do not contain the _id field, one will be added to each of the documents missing it by the driver, mutating the document. This behavior can be overridden by setting the forceServerObjectId flag.
Bulk operations to perform
An estimated count of matching documents in the db to a filter.
NOTE: This method has been deprecated, since it does not provide an accurate count of the documents in a collection. To obtain an accurate count of documents in the collection, use {@link Collection#countDocuments| countDocuments}. To obtain an estimated count of all documents in the collection, use {@link Collection#estimatedDocumentCount| estimatedDocumentCount}.
Gets the number of documents matching the filter. For a fast count of the total documents in a collection see {@link Collection#estimatedDocumentCount| estimatedDocumentCount}. Note: When migrating from {@link Collection#count| count} to {@link Collection#countDocuments| countDocuments} the following query operators must be replaced:
Operator | Replacement |
---|---|
$where |
[$expr ][1] |
$near |
[$geoWithin ][2] with [$center ][3] |
$nearSphere |
[$geoWithin ][2] with [$centerSphere ][4] |
Creates an index on the db and collection collection.
The field name or index specification to create an index for
Creates multiple indexes in the collection, this method is only supported for MongoDB 2.6 or higher. Earlier version of MongoDB will throw a command not supported error.
Note: Unlike {@link Collection#createIndex| createIndex}, this function takes in raw index specifications. Index specifications are defined here.
An array of index specifications to be created
Delete multiple documents from a collection
The filter used to select the documents to remove
Delete a document from a collection
The filter used to select the document to remove
The distinct command returns a list of distinct values for the given key across a collection.
Field of the document to find distinct values for
Drop the collection from the database, removing it permanently. New accesses will create a new collection.
Drops an index from this collection.
Name of the index to drop.
Drops all indexes from this collection.
Gets an estimate of the count of documents in a collection using collection metadata.
Creates a cursor for a filter that can be used to iterate over results from MongoDB
Fetches the first document that matches the filter
Find a document and delete it in one atomic operation. Requires a write lock for the duration of the operation.
The filter used to select the document to remove
Find a document and replace it in one atomic operation. Requires a write lock for the duration of the operation.
The filter used to select the document to replace
The Document that replaces the matching document
Find a document and update it in one atomic operation. Requires a write lock for the duration of the operation.
The filter used to select the document to update
Update operations to be performed on the document
Get the db scoped logger
Checks if one or more indexes exist on the collection, fails on first non-existing index
One or more index names to check.
Retrieves this collections index info.
Retrieve all the indexes on the collection.
Initiate an In order bulk write operation. Operations will be serially executed in the order they are added, creating a new operation for each switch in types.
Initiate an Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order.
Inserts a single document or a an array of documents into MongoDB. If documents passed in do not contain the _id field, one will be added to each of the documents missing it by the driver, mutating the document. This behavior can be overridden by setting the forceServerObjectId flag.
The documents to insert
Optional settings for the command
An optional callback, a Promise will be returned if none is provided
Inserts an array of documents into MongoDB. If documents passed in do not contain the _id field, one will be added to each of the documents missing it by the driver, mutating the document. This behavior can be overridden by setting the forceServerObjectId flag.
The documents to insert
Inserts a single document into MongoDB. If documents passed in do not contain the _id field, one will be added to each of the documents missing it by the driver, mutating the document. This behavior can be overridden by setting the forceServerObjectId flag.
The document to insert
Returns if the collection is a capped collection
Get the list of all indexes information for the collection.
Optional settings for the command
Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.
The mapping function.
The reduce function.
Returns the options of the collection.
Remove documents.
The selector for the update operation.
Optional settings for the command
An optional callback, a Promise will be returned if none is provided
Rename the collection.
New name of of the collection.
Replace a document in a collection with another document
The filter used to select the document to replace
The Document that replaces the matching document
Get all the collection statistics.
Updates documents.
The selector for the update operation.
The update operations to be applied to the documents
Optional settings for the command
An optional callback, a Promise will be returned if none is provided
Update multiple documents in a collection
The filter used to select the documents to update
The update operations to be applied to the documents
Update a single document in a collection
The filter used to select the document to update
The update operations to be applied to the document
Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this collection.
An array of aggregation pipeline stages through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
Optional settings for the command
Generated using TypeDoc
The Collection class is an internal class that embodies a MongoDB collection allowing for insert/update/remove/find and other command operation on that MongoDB collection.
COLLECTION Cannot directly be instantiated