import { BSONSerializeOptions, Document } from './bson'; import type { AnyBulkWriteOperation, BulkWriteOptions, BulkWriteResult } from './bulk/common'; import { OrderedBulkOperation } from './bulk/ordered'; import { UnorderedBulkOperation } from './bulk/unordered'; import { ChangeStream, ChangeStreamDocument, ChangeStreamOptions } from './change_stream'; import { AggregationCursor } from './cursor/aggregation_cursor'; import { FindCursor } from './cursor/find_cursor'; import { ListIndexesCursor } from './cursor/list_indexes_cursor'; import type { Db } from './db'; import type { Logger, LoggerOptions } from './logger'; import type { PkFactory } from './mongo_client'; import type { Filter, Flatten, OptionalUnlessRequiredId, UpdateFilter, WithId, WithoutId } from './mongo_types'; import type { AggregateOptions } from './operations/aggregate'; import type { IndexInformationOptions } from './operations/common_functions'; import { CountOptions } from './operations/count'; import { CountDocumentsOptions } from './operations/count_documents'; import { DeleteOptions, DeleteResult } from './operations/delete'; import { DistinctOptions } from './operations/distinct'; import { DropCollectionOptions } from './operations/drop'; import { EstimatedDocumentCountOptions } from './operations/estimated_document_count'; import type { FindOptions } from './operations/find'; import { FindOneAndDeleteOptions, FindOneAndReplaceOptions, FindOneAndUpdateOptions } from './operations/find_and_modify'; import { CreateIndexesOptions, DropIndexesOptions, IndexDescription, IndexSpecification, ListIndexesOptions } from './operations/indexes'; import { InsertManyResult, InsertOneOptions, InsertOneResult } from './operations/insert'; import { MapFunction, MapReduceOptions, ReduceFunction } from './operations/map_reduce'; import type { Hint, OperationOptions } from './operations/operation'; import { RenameOptions } from './operations/rename'; import { CollStats, CollStatsOptions } from './operations/stats'; import { ReplaceOptions, UpdateOptions, UpdateResult } from './operations/update'; import { ReadConcern, ReadConcernLike } from './read_concern'; import { ReadPreference, ReadPreferenceLike } from './read_preference'; import { Callback, MongoDBNamespace } from './utils'; import { WriteConcern, WriteConcernOptions } from './write_concern'; /** @public */ export interface ModifyResult { value: WithId | null; lastErrorObject?: Document; ok: 0 | 1; } /** @public */ export interface CollectionOptions extends BSONSerializeOptions, WriteConcernOptions, LoggerOptions { /** * @deprecated Use readPreference instead */ slaveOk?: boolean; /** Specify a read concern for the collection. (only MongoDB 3.2 or higher supported) */ readConcern?: ReadConcernLike; /** The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). */ readPreference?: ReadPreferenceLike; } /** @internal */ export interface CollectionPrivate { pkFactory: PkFactory; db: Db; options: any; namespace: MongoDBNamespace; readPreference?: ReadPreference; bsonOptions: BSONSerializeOptions; collectionHint?: Hint; readConcern?: ReadConcern; writeConcern?: WriteConcern; } /** * 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** * @public * * @example * ```js * const MongoClient = require('mongodb').MongoClient; * const test = require('assert'); * // Connection url * const url = 'mongodb://localhost:27017'; * // Database Name * const dbName = 'test'; * // Connect using MongoClient * MongoClient.connect(url, function(err, client) { * // Create a collection we want to drop later * const col = client.db(dbName).collection('createIndexExample1'); * // Show that duplicate records got dropped * col.find({}).toArray(function(err, items) { * expect(err).to.not.exist; * test.equal(4, items.length); * client.close(); * }); * }); * ``` */ export declare class Collection { /** @internal */ s: CollectionPrivate; /** * Create a new Collection instance * @internal */ constructor(db: Db, name: string, options?: CollectionOptions); /** * The name of the database this collection belongs to */ get dbName(): string; /** * The name of this collection */ get collectionName(): string; /** * The namespace of this collection, in the format `${this.dbName}.${this.collectionName}` */ get namespace(): string; /** * The current readConcern of the collection. If not explicitly defined for * this collection, will be inherited from the parent DB */ get readConcern(): ReadConcern | undefined; /** * The current readPreference of the collection. If not explicitly defined for * this collection, will be inherited from the parent DB */ get readPreference(): ReadPreference | undefined; get bsonOptions(): BSONSerializeOptions; /** * The current writeConcern of the collection. If not explicitly defined for * this collection, will be inherited from the parent DB */ get writeConcern(): WriteConcern | undefined; /** The current index hint for the collection */ get hint(): Hint | undefined; set hint(v: Hint | undefined); /** * 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. * * @param doc - The document to insert * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ insertOne(doc: OptionalUnlessRequiredId): Promise>; insertOne(doc: OptionalUnlessRequiredId, callback: Callback>): void; insertOne(doc: OptionalUnlessRequiredId, options: InsertOneOptions): Promise>; insertOne(doc: OptionalUnlessRequiredId, options: InsertOneOptions, callback: Callback>): void; /** * 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. * * @param docs - The documents to insert * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ insertMany(docs: OptionalUnlessRequiredId[]): Promise>; insertMany(docs: OptionalUnlessRequiredId[], callback: Callback>): void; insertMany(docs: OptionalUnlessRequiredId[], options: BulkWriteOptions): Promise>; insertMany(docs: OptionalUnlessRequiredId[], options: BulkWriteOptions, callback: Callback>): void; /** * Perform a bulkWrite operation without a fluent API * * Legal operation types are * * ```js * { 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. * * @param operations - Bulk operations to perform * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided * @throws MongoDriverError if operations is not an array */ bulkWrite(operations: AnyBulkWriteOperation[]): Promise; bulkWrite(operations: AnyBulkWriteOperation[], callback: Callback): void; bulkWrite(operations: AnyBulkWriteOperation[], options: BulkWriteOptions): Promise; bulkWrite(operations: AnyBulkWriteOperation[], options: BulkWriteOptions, callback: Callback): void; /** * Update a single document in a collection * * @param filter - The filter used to select the document to update * @param update - The update operations to be applied to the document * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ updateOne(filter: Filter, update: UpdateFilter | Partial): Promise; updateOne(filter: Filter, update: UpdateFilter | Partial, callback: Callback): void; updateOne(filter: Filter, update: UpdateFilter | Partial, options: UpdateOptions): Promise; updateOne(filter: Filter, update: UpdateFilter | Partial, options: UpdateOptions, callback: Callback): void; /** * Replace a document in a collection with another document * * @param filter - The filter used to select the document to replace * @param replacement - The Document that replaces the matching document * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ replaceOne(filter: Filter, replacement: WithoutId): Promise; replaceOne(filter: Filter, replacement: WithoutId, callback: Callback): void; replaceOne(filter: Filter, replacement: WithoutId, options: ReplaceOptions): Promise; replaceOne(filter: Filter, replacement: WithoutId, options: ReplaceOptions, callback: Callback): void; /** * Update multiple documents in a collection * * @param filter - The filter used to select the documents to update * @param update - The update operations to be applied to the documents * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ updateMany(filter: Filter, update: UpdateFilter): Promise; updateMany(filter: Filter, update: UpdateFilter, callback: Callback): void; updateMany(filter: Filter, update: UpdateFilter, options: UpdateOptions): Promise; updateMany(filter: Filter, update: UpdateFilter, options: UpdateOptions, callback: Callback): void; /** * Delete a document from a collection * * @param filter - The filter used to select the document to remove * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ deleteOne(filter: Filter): Promise; deleteOne(filter: Filter, callback: Callback): void; deleteOne(filter: Filter, options: DeleteOptions): Promise; deleteOne(filter: Filter, options: DeleteOptions, callback?: Callback): void; /** * Delete multiple documents from a collection * * @param filter - The filter used to select the documents to remove * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ deleteMany(filter: Filter): Promise; deleteMany(filter: Filter, callback: Callback): void; deleteMany(filter: Filter, options: DeleteOptions): Promise; deleteMany(filter: Filter, options: DeleteOptions, callback: Callback): void; /** * Rename the collection. * * @remarks * This operation does not inherit options from the Db or MongoClient. * * @param newName - New name of of the collection. * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ rename(newName: string): Promise; rename(newName: string, callback: Callback): void; rename(newName: string, options: RenameOptions): Promise; rename(newName: string, options: RenameOptions, callback: Callback): void; /** * Drop the collection from the database, removing it permanently. New accesses will create a new collection. * * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ drop(): Promise; drop(callback: Callback): void; drop(options: DropCollectionOptions): Promise; drop(options: DropCollectionOptions, callback: Callback): void; /** * Fetches the first document that matches the filter * * @param filter - Query for find Operation * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ findOne(): Promise | null>; findOne(callback: Callback | null>): void; findOne(filter: Filter): Promise | null>; findOne(filter: Filter, callback: Callback | null>): void; findOne(filter: Filter, options: FindOptions): Promise | null>; findOne(filter: Filter, options: FindOptions, callback: Callback | null>): void; findOne(): Promise; findOne(callback: Callback): void; findOne(filter: Filter): Promise; findOne(filter: Filter, options?: FindOptions): Promise; findOne(filter: Filter, options?: FindOptions, callback?: Callback): void; /** * Creates a cursor for a filter that can be used to iterate over results from MongoDB * * @param filter - The filter predicate. If unspecified, then all documents in the collection will match the predicate */ find(): FindCursor>; find(filter: Filter, options?: FindOptions): FindCursor>; find(filter: Filter, options?: FindOptions): FindCursor; /** * Returns the options of the collection. * * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ options(): Promise; options(callback: Callback): void; options(options: OperationOptions): Promise; options(options: OperationOptions, callback: Callback): void; /** * Returns if the collection is a capped collection * * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ isCapped(): Promise; isCapped(callback: Callback): void; isCapped(options: OperationOptions): Promise; isCapped(options: OperationOptions, callback: Callback): void; /** * Creates an index on the db and collection collection. * * @param indexSpec - The field name or index specification to create an index for * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided * * @example * ```js * const collection = client.db('foo').collection('bar'); * * await collection.createIndex({ a: 1, b: -1 }); * * // Alternate syntax for { c: 1, d: -1 } that ensures order of indexes * await collection.createIndex([ [c, 1], [d, -1] ]); * * // Equivalent to { e: 1 } * await collection.createIndex('e'); * * // Equivalent to { f: 1, g: 1 } * await collection.createIndex(['f', 'g']) * * // Equivalent to { h: 1, i: -1 } * await collection.createIndex([ { h: 1 }, { i: -1 } ]); * * // Equivalent to { j: 1, k: -1, l: 2d } * await collection.createIndex(['j', ['k', -1], { l: '2d' }]) * ``` */ createIndex(indexSpec: IndexSpecification): Promise; createIndex(indexSpec: IndexSpecification, callback: Callback): void; createIndex(indexSpec: IndexSpecification, options: CreateIndexesOptions): Promise; createIndex(indexSpec: IndexSpecification, options: CreateIndexesOptions, callback: Callback): void; /** * 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 {@link http://docs.mongodb.org/manual/reference/command/createIndexes/| here}. * * @param indexSpecs - An array of index specifications to be created * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided * * @example * ```js * const collection = client.db('foo').collection('bar'); * await collection.createIndexes([ * // Simple index on field fizz * { * key: { fizz: 1 }, * } * // wildcard index * { * key: { '$**': 1 } * }, * // named index on darmok and jalad * { * key: { darmok: 1, jalad: -1 } * name: 'tanagra' * } * ]); * ``` */ createIndexes(indexSpecs: IndexDescription[]): Promise; createIndexes(indexSpecs: IndexDescription[], callback: Callback): void; createIndexes(indexSpecs: IndexDescription[], options: CreateIndexesOptions): Promise; createIndexes(indexSpecs: IndexDescription[], options: CreateIndexesOptions, callback: Callback): void; /** * Drops an index from this collection. * * @param indexName - Name of the index to drop. * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ dropIndex(indexName: string): Promise; dropIndex(indexName: string, callback: Callback): void; dropIndex(indexName: string, options: DropIndexesOptions): Promise; dropIndex(indexName: string, options: DropIndexesOptions, callback: Callback): void; /** * Drops all indexes from this collection. * * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ dropIndexes(): Promise; dropIndexes(callback: Callback): void; dropIndexes(options: DropIndexesOptions): Promise; dropIndexes(options: DropIndexesOptions, callback: Callback): void; /** * Get the list of all indexes information for the collection. * * @param options - Optional settings for the command */ listIndexes(options?: ListIndexesOptions): ListIndexesCursor; /** * Checks if one or more indexes exist on the collection, fails on first non-existing index * * @param indexes - One or more index names to check. * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ indexExists(indexes: string | string[]): Promise; indexExists(indexes: string | string[], callback: Callback): void; indexExists(indexes: string | string[], options: IndexInformationOptions): Promise; indexExists(indexes: string | string[], options: IndexInformationOptions, callback: Callback): void; /** * Retrieves this collections index info. * * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ indexInformation(): Promise; indexInformation(callback: Callback): void; indexInformation(options: IndexInformationOptions): Promise; indexInformation(options: IndexInformationOptions, callback: Callback): void; /** * Gets an estimate of the count of documents in a collection using collection metadata. * This will always run a count command on all server versions. * * due to an oversight in versions 5.0.0-5.0.8 of MongoDB, the count command, * which estimatedDocumentCount uses in its implementation, was not included in v1 of * the Stable API, and so users of the Stable API with estimatedDocumentCount are * recommended to upgrade their server version to 5.0.9+ or set apiStrict: false to avoid * encountering errors. * * @see {@link https://www.mongodb.com/docs/manual/reference/command/count/#behavior|Count: Behavior} * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ estimatedDocumentCount(): Promise; estimatedDocumentCount(callback: Callback): void; estimatedDocumentCount(options: EstimatedDocumentCountOptions): Promise; estimatedDocumentCount(options: EstimatedDocumentCountOptions, callback: Callback): void; /** * 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] | * * [1]: https://docs.mongodb.com/manual/reference/operator/query/expr/ * [2]: https://docs.mongodb.com/manual/reference/operator/query/geoWithin/ * [3]: https://docs.mongodb.com/manual/reference/operator/query/center/#op._S_center * [4]: https://docs.mongodb.com/manual/reference/operator/query/centerSphere/#op._S_centerSphere * * @param filter - The filter for the count * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided * * @see https://docs.mongodb.com/manual/reference/operator/query/expr/ * @see https://docs.mongodb.com/manual/reference/operator/query/geoWithin/ * @see https://docs.mongodb.com/manual/reference/operator/query/center/#op._S_center * @see https://docs.mongodb.com/manual/reference/operator/query/centerSphere/#op._S_centerSphere */ countDocuments(): Promise; countDocuments(callback: Callback): void; countDocuments(filter: Filter): Promise; countDocuments(callback: Callback): void; countDocuments(filter: Filter, options: CountDocumentsOptions): Promise; countDocuments(filter: Filter, options: CountDocumentsOptions, callback: Callback): void; countDocuments(filter: Filter, callback: Callback): void; /** * The distinct command returns a list of distinct values for the given key across a collection. * * @param key - Field of the document to find distinct values for * @param filter - The filter for filtering the set of documents to which we apply the distinct filter. * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ distinct>(key: Key): Promise[Key]>>>; distinct>(key: Key, callback: Callback[Key]>>>): void; distinct>(key: Key, filter: Filter): Promise[Key]>>>; distinct>(key: Key, filter: Filter, callback: Callback[Key]>>>): void; distinct>(key: Key, filter: Filter, options: DistinctOptions): Promise[Key]>>>; distinct>(key: Key, filter: Filter, options: DistinctOptions, callback: Callback[Key]>>>): void; distinct(key: string): Promise; distinct(key: string, callback: Callback): void; distinct(key: string, filter: Filter): Promise; distinct(key: string, filter: Filter, callback: Callback): void; distinct(key: string, filter: Filter, options: DistinctOptions): Promise; distinct(key: string, filter: Filter, options: DistinctOptions, callback: Callback): void; /** * Retrieve all the indexes on the collection. * * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ indexes(): Promise; indexes(callback: Callback): void; indexes(options: IndexInformationOptions): Promise; indexes(options: IndexInformationOptions, callback: Callback): void; /** * Get all the collection statistics. * * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ stats(): Promise; stats(callback: Callback): void; stats(options: CollStatsOptions): Promise; stats(options: CollStatsOptions, callback: Callback): void; /** * Find a document and delete it in one atomic operation. Requires a write lock for the duration of the operation. * * @param filter - The filter used to select the document to remove * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ findOneAndDelete(filter: Filter): Promise>; findOneAndDelete(filter: Filter, options: FindOneAndDeleteOptions): Promise>; findOneAndDelete(filter: Filter, callback: Callback>): void; findOneAndDelete(filter: Filter, options: FindOneAndDeleteOptions, callback: Callback>): void; /** * Find a document and replace it in one atomic operation. Requires a write lock for the duration of the operation. * * @param filter - The filter used to select the document to replace * @param replacement - The Document that replaces the matching document * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ findOneAndReplace(filter: Filter, replacement: WithoutId): Promise>; findOneAndReplace(filter: Filter, replacement: WithoutId, callback: Callback>): void; findOneAndReplace(filter: Filter, replacement: WithoutId, options: FindOneAndReplaceOptions): Promise>; findOneAndReplace(filter: Filter, replacement: WithoutId, options: FindOneAndReplaceOptions, callback: Callback>): void; /** * Find a document and update it in one atomic operation. Requires a write lock for the duration of the operation. * * @param filter - The filter used to select the document to update * @param update - Update operations to be performed on the document * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ findOneAndUpdate(filter: Filter, update: UpdateFilter): Promise>; findOneAndUpdate(filter: Filter, update: UpdateFilter, callback: Callback>): void; findOneAndUpdate(filter: Filter, update: UpdateFilter, options: FindOneAndUpdateOptions): Promise>; findOneAndUpdate(filter: Filter, update: UpdateFilter, options: FindOneAndUpdateOptions, callback: Callback>): void; /** * Execute an aggregation framework pipeline against the collection, needs MongoDB \>= 2.2 * * @param pipeline - An array of aggregation pipelines to execute * @param options - Optional settings for the command */ aggregate(pipeline?: Document[], options?: AggregateOptions): AggregationCursor; /** * Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this collection. * * @remarks * watch() accepts two generic arguments for distinct usecases: * - The first is to override the schema that may be defined for this specific collection * - The second is to override the shape of the change stream document entirely, if it is not provided the type will default to ChangeStreamDocument of the first argument * @example * By just providing the first argument I can type the change to be `ChangeStreamDocument<{ _id: number }>` * ```ts * collection.watch<{ _id: number }>() * .on('change', change => console.log(change._id.toFixed(4))); * ``` * * @example * Passing a second argument provides a way to reflect the type changes caused by an advanced pipeline. * Here, we are using a pipeline to have MongoDB filter for insert changes only and add a comment. * No need start from scratch on the ChangeStreamInsertDocument type! * By using an intersection we can save time and ensure defaults remain the same type! * ```ts * collection * .watch & { comment: string }>([ * { $addFields: { comment: 'big changes' } }, * { $match: { operationType: 'insert' } } * ]) * .on('change', change => { * change.comment.startsWith('big'); * change.operationType === 'insert'; * // No need to narrow in code because the generics did that for us! * expectType(change.fullDocument); * }); * ``` * * @param pipeline - An array of {@link https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents. * @param options - Optional settings for the command * @typeParam TLocal - Type of the data being detected by the change stream * @typeParam TChange - Type of the whole change stream document emitted */ watch>(pipeline?: Document[], options?: ChangeStreamOptions): ChangeStream; /** * Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection. * * @deprecated collection.mapReduce is deprecated. Use the aggregation pipeline instead. Visit https://docs.mongodb.com/manual/reference/map-reduce-to-aggregation-pipeline for more information on how to translate map-reduce operations to the aggregation pipeline. * @param map - The mapping function. * @param reduce - The reduce function. * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ mapReduce(map: string | MapFunction, reduce: string | ReduceFunction): Promise; mapReduce(map: string | MapFunction, reduce: string | ReduceFunction, callback: Callback): void; mapReduce(map: string | MapFunction, reduce: string | ReduceFunction, options: MapReduceOptions): Promise; mapReduce(map: string | MapFunction, reduce: string | ReduceFunction, options: MapReduceOptions, callback: Callback): void; /** * Initiate an Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order. * * @throws MongoNotConnectedError * @remarks * **NOTE:** MongoClient must be connected prior to calling this method due to a known limitation in this legacy implemenation. * However, `collection.bulkWrite()` provides an equivalent API that does not require prior connecting. */ initializeUnorderedBulkOp(options?: BulkWriteOptions): UnorderedBulkOperation; /** * 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. * * @throws MongoNotConnectedError * @remarks * **NOTE:** MongoClient must be connected prior to calling this method due to a known limitation in this legacy implemenation. * However, `collection.bulkWrite()` provides an equivalent API that does not require prior connecting. */ initializeOrderedBulkOp(options?: BulkWriteOptions): OrderedBulkOperation; /** Get the db scoped logger */ getLogger(): Logger; get logger(): Logger; /** * 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. * * @deprecated Use insertOne, insertMany or bulkWrite instead. * @param docs - The documents to insert * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ insert(docs: OptionalUnlessRequiredId[], options: BulkWriteOptions, callback: Callback>): Promise> | void; /** * Updates documents. * * @deprecated use updateOne, updateMany or bulkWrite * @param selector - The selector for the update operation. * @param update - The update operations to be applied to the documents * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ update(selector: Filter, update: UpdateFilter, options: UpdateOptions, callback: Callback): Promise | void; /** * Remove documents. * * @deprecated use deleteOne, deleteMany or bulkWrite * @param selector - The selector for the update operation. * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ remove(selector: Filter, options: DeleteOptions, callback: Callback): Promise | void; /** * 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}. * * @deprecated use {@link Collection#countDocuments| countDocuments} or {@link Collection#estimatedDocumentCount| estimatedDocumentCount} instead * * @param filter - The filter for the count. * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ count(): Promise; count(callback: Callback): void; count(filter: Filter): Promise; count(filter: Filter, callback: Callback): void; count(filter: Filter, options: CountOptions): Promise; count(filter: Filter, options: CountOptions, callback: Callback): Promise | void; } //# sourceMappingURL=collection.d.ts.map