new Collection(){Collection}
Create a new Collection instance (INTERNAL TYPE, do not instantiate directly)
Properties:
| Name | Type | Description | 
|---|---|---|
| collectionName | string | Get the collection name. | 
| namespace | string | Get the full collection namespace. | 
| writeConcern | object | The current write concern values. | 
| readConcern | object | The current read concern values. | 
| hint | object | Get current index hint for collection. | 
Returns:
Collection instance.Methods
- 
    aggregate(pipeline, options, callback){null|AggregationCursor}
- 
    
    
    Execute an aggregation framework pipeline against the collection, needs MongoDB >= 2.2 Name Type Default Description pipelineobject Array containing all the aggregation framework commands for the execution. optionsobject null optional Optional settings. Name Type Default Description readPreferenceReadPreference | string null optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). cursorobject null optional Return the query as cursor, on 2.6 > it returns as a real cursor on pre 2.6 it returns as an emulated cursor. Name Type Default Description batchSizenumber null optional The batchSize for the cursor explainboolean false optional Explain returns the aggregation execution plan (requires mongodb 2.6 >). allowDiskUseboolean false optional allowDiskUse lets the server know if it can use disk to store temporary results for the aggregation (requires mongodb 2.6 >). maxTimeMSnumber null optional maxTimeMS specifies a cumulative time limit in milliseconds for processing operations on the cursor. MongoDB interrupts the operation at the earliest following interrupt point. bypassDocumentValidationboolean false optional Allow driver to bypass schema validation in MongoDB 3.2 or higher. rawboolean false optional Return document results as raw BSON buffers. promoteLongsboolean true optional Promotes Long values to number if they fit inside the 53 bits resolution. promoteValuesboolean true optional Promotes BSON values to native types where possible, set to false to only receive wrapper types. promoteBuffersboolean false optional Promotes Binary BSON values to native Node Buffers. collationobject null optional Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields). commentstring optional Add a comment to an aggregation command sessionClientSession optional optional session to use for this operation callbackCollection~aggregationCallback The command result callback 
- 
    bulkWrite(operations, options, callback){Promise}
- 
    
    
    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 } } { deleteOne: { filter: {c:1} } } { deleteMany: { filter: {c:1} } } { replaceOne: { filter: {c:3}, replacement: {c:4}, upsert:true}} 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.Name Type Default Description operationsArray.<object> Bulk operations to perform. optionsobject null optional Optional settings. Name Type Default Description wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. serializeFunctionsboolean false optional Serialize functions on any object. orderedboolean true optional Execute write operation in ordered or unordered fashion. bypassDocumentValidationboolean false optional Allow driver to bypass schema validation in MongoDB 3.2 or higher. sessionClientSession optional optional session to use for this operation callbackCollection~bulkWriteOpCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    count(query, options, callback){Promise}
- 
    
    
    Count number of matching documents in the db to a query. Name Type Default Description queryobject The query for the count. optionsobject null optional Optional settings. Name Type Default Description limitboolean null optional The limit of documents to count. skipboolean null optional The number of documents to skip for the count. hintstring null optional An index name hint for the query. readPreferenceReadPreference | string null optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). maxTimeMSnumber null optional Number of miliseconds to wait before aborting the query. sessionClientSession optional optional session to use for this operation callbackCollection~countCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    createIndex(fieldOrSpec, options, callback){Promise}
- 
    
    
    Creates an index on the db and collection collection. Name Type Default Description fieldOrSpecstring | object Defines the index. optionsobject null optional Optional settings. Name Type Default Description wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. uniqueboolean false optional Creates an unique index. sparseboolean false optional Creates a sparse index. backgroundboolean false optional Creates the index in the background, yielding whenever possible. dropDupsboolean false optional A unique index cannot be created on a key that has pre-existing duplicate values. If you would like to create the index anyway, keeping the first document the database indexes and deleting all subsequent documents that have duplicate value minnumber null optional For geospatial indexes set the lower bound for the co-ordinates. maxnumber null optional For geospatial indexes set the high bound for the co-ordinates. vnumber null optional Specify the format version of the indexes. expireAfterSecondsnumber null optional Allows you to expire data on indexes applied to a data (MongoDB 2.2 or higher) namestring null optional Override the autogenerated index name (useful if the resulting name is larger than 128 bytes) partialFilterExpressionobject null optional Creates a partial index based on the given filter object (MongoDB 3.2 or higher) collationobject null optional Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields). sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    createIndexes(indexSpecs, options, callback){Promise}
- 
    
    
    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. Index specifications are defined at https://www.mongodb.com/docs/manual/reference/command/createIndexes/.Name Type Description indexSpecsarray An array of index specifications to be created optionsObject optional Optional settings Name Type Description sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    deleteMany(filter, options, callback){Promise}
- 
    
    
    Delete multiple documents on MongoDB Name Type Default Description filterobject The Filter used to select the documents to remove optionsobject null optional Optional settings. Name Type Default Description wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. sessionClientSession optional optional session to use for this operation callbackCollection~deleteWriteOpCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    deleteOne(filter, options, callback){Promise}
- 
    
    
    Delete a document on MongoDB Name Type Default Description filterobject The Filter used to select the document to remove optionsobject null optional Optional settings. Name Type Default Description wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. sessionClientSession optional optional session to use for this operation callbackCollection~deleteWriteOpCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    distinct(key, query, options, callback){Promise}
- 
    
    
    The distinct command returns returns a list of distinct values for the given key across a collection. Name Type Default Description keystring Field of the document to find distinct values for. queryobject The query for filtering the set of documents to which we apply the distinct filter. optionsobject null optional Optional settings. Name Type Default Description readPreferenceReadPreference | string null optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). maxTimeMSnumber null optional Number of miliseconds to wait before aborting the query. sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    drop(options, callback){Promise}
- 
    
    
    Drop the collection from the database, removing it permanently. New accesses will create a new collection. Name Type Default Description optionsobject null optional Optional settings. Name Type Description sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The results callback Returns:Promise if no callback passed
 
- 
    dropAllIndexes(callback){Promise}
- 
    
    
    Drops all indexes from this collection. Name Type Description callbackCollection~resultCallback The command result callback - Deprecated
- use dropIndexes
 
 Returns:Promise if no [callback] passed
 
- 
    dropIndex(indexName, options, callback){Promise}
- 
    
    
    Drops an index from this collection. Name Type Default Description indexNamestring Name of the index to drop. optionsobject null optional Optional settings. Name Type Default Description wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. sessionClientSession optional optional session to use for this operation maxTimeMSnumber optional Number of miliseconds to wait before aborting the query. callbackCollection~resultCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    dropIndexes(options, callback){Promise}
- 
    
    
    Drops all indexes from this collection. Name Type Description optionsObject optional Optional settings Name Type Description sessionClientSession optional optional session to use for this operation maxTimeMSnumber optional Number of miliseconds to wait before aborting the query. callbackCollection~resultCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    ensureIndex(fieldOrSpec, options, callback){Promise}
- 
    
    
    Ensures that an index exists, if it does not it creates it Name Type Default Description fieldOrSpecstring | object Defines the index. optionsobject null optional Optional settings. Name Type Default Description wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. uniqueboolean false optional Creates an unique index. sparseboolean false optional Creates a sparse index. backgroundboolean false optional Creates the index in the background, yielding whenever possible. dropDupsboolean false optional A unique index cannot be created on a key that has pre-existing duplicate values. If you would like to create the index anyway, keeping the first document the database indexes and deleting all subsequent documents that have duplicate value minnumber null optional For geospatial indexes set the lower bound for the co-ordinates. maxnumber null optional For geospatial indexes set the high bound for the co-ordinates. vnumber null optional Specify the format version of the indexes. expireAfterSecondsnumber null optional Allows you to expire data on indexes applied to a data (MongoDB 2.2 or higher) namenumber null optional Override the autogenerated index name (useful if the resulting name is larger than 128 bytes) collationobject null optional Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields). sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The command result callback - Deprecated
- use createIndexes instead
 
 Returns:Promise if no callback passed
 
- 
    find(query, options){Cursor}
- 
    
    
    Creates a cursor for a query that can be used to iterate over results from MongoDB Name Type Default Description queryobject {} optional The cursor query object. optionsobject null optional Optional settings. Name Type Default Description limitnumber 0 optional Sets the limit of documents returned in the query. sortarray | object null optional Set to sort the documents coming back from the query. Array of indexes, [['a', 1]] etc. projectionobject null optional The fields to return in the query. Object of fields to include or exclude (not both), {'a':1} fieldsobject null optional Deprecated Use options.projectioninsteadskipnumber 0 optional Set to skip N documents ahead in your query (useful for pagination). hintObject null optional Tell the query to use specific indexes in the query. Object of indexes to use, {'_id':1} explainboolean false optional Explain the query instead of returning the data. snapshotboolean false optional Snapshot query. timeoutboolean false optional Specify if the cursor can timeout. tailableboolean false optional Specify if the cursor is tailable. batchSizenumber 0 optional Set the batchSize for the getMoreCommand when iterating over the query results. returnKeyboolean false optional Only return the index key. maxScannumber null optional Limit the number of items to scan. minnumber null optional Set index bounds. maxnumber null optional Set index bounds. showDiskLocboolean false optional Show disk location of results. commentstring null optional You can put a $comment field on a query to make looking in the profiler logs simpler. rawboolean false optional Return document results as raw BSON buffers. promoteLongsboolean true optional Promotes Long values to number if they fit inside the 53 bits resolution. promoteValuesboolean true optional Promotes BSON values to native types where possible, set to false to only receive wrapper types. promoteBuffersboolean false optional Promotes Binary BSON values to native Node Buffers. readPreferenceReadPreference | string null optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). partialboolean false optional Specify if the cursor should return partial results when querying against a sharded system maxTimeMSnumber null optional Number of miliseconds to wait before aborting the query. collationobject null optional Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields). sessionClientSession optional optional session to use for this operation Throws:
- 
    findAndModify(query, sort, doc, options, callback){Promise}
- 
    
    
    Find and update a document. Name Type Default Description queryobject Query object to locate the object to modify. sortarray If multiple docs match, choose the first one in the specified sort order as the object to manipulate. docobject The fields/vals to be updated. optionsobject null optional Optional settings. Name Type Default Description wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. removeboolean false optional Set to true to remove the object before returning. upsertboolean false optional Perform an upsert operation. newboolean false optional Set to true if you want to return the modified object rather than the original. Ignored for remove. projectionobject null optional Object containing the field projection for the result returned from the operation. fieldsobject null optional Deprecated Use options.projectioninsteadsessionClientSession optional optional session to use for this operation callbackCollection~findAndModifyCallback optional The command result callback - Deprecated
- use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead
 
 Returns:Promise if no callback passed
 
- 
    findAndRemove(query, sort, options, callback){Promise}
- 
    
    
    Find and remove a document. Name Type Default Description queryobject Query object to locate the object to modify. sortarray If multiple docs match, choose the first one in the specified sort order as the object to manipulate. optionsobject null optional Optional settings. Name Type Default Description wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The command result callback - Deprecated
- use findOneAndDelete instead
 
 Returns:Promise if no callback passed
 
- 
    findOne(query, options, callback){Promise}
- 
    
    
    Fetches the first document that matches the query Name Type Default Description queryobject Query for find Operation optionsobject null optional Optional settings. Name Type Default Description limitnumber 0 optional Sets the limit of documents returned in the query. sortarray | object null optional Set to sort the documents coming back from the query. Array of indexes, [['a', 1]] etc. projectionobject null optional The fields to return in the query. Object of fields to include or exclude (not both), {'a':1} fieldsobject null optional Deprecated Use options.projectioninsteadskipnumber 0 optional Set to skip N documents ahead in your query (useful for pagination). hintObject null optional Tell the query to use specific indexes in the query. Object of indexes to use, {'_id':1} explainboolean false optional Explain the query instead of returning the data. snapshotboolean false optional Snapshot query. timeoutboolean false optional Specify if the cursor can timeout. tailableboolean false optional Specify if the cursor is tailable. batchSizenumber 0 optional Set the batchSize for the getMoreCommand when iterating over the query results. returnKeyboolean false optional Only return the index key. maxScannumber null optional Limit the number of items to scan. minnumber null optional Set index bounds. maxnumber null optional Set index bounds. showDiskLocboolean false optional Show disk location of results. commentstring null optional You can put a $comment field on a query to make looking in the profiler logs simpler. rawboolean false optional Return document results as raw BSON buffers. promoteLongsboolean true optional Promotes Long values to number if they fit inside the 53 bits resolution. promoteValuesboolean true optional Promotes BSON values to native types where possible, set to false to only receive wrapper types. promoteBuffersboolean false optional Promotes Binary BSON values to native Node Buffers. readPreferenceReadPreference | string null optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). partialboolean false optional Specify if the cursor should return partial results when querying against a sharded system maxTimeMSnumber null optional Number of miliseconds to wait before aborting the query. collationobject null optional Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields). sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    findOneAndDelete(filter, options, callback){Promise}
- 
    
    
    Find a document and delete it in one atomic operation, requires a write lock for the duration of the operation. Name Type Default Description filterobject Document selection filter. optionsobject null optional Optional settings. Name Type Default Description projectionobject null optional Limits the fields to return for all matching documents. sortobject null optional Determines which document the operation modifies if the query selects multiple documents. maxTimeMSnumber null optional The maximum amount of time to allow the query to run. sessionClientSession optional optional session to use for this operation callbackCollection~findAndModifyCallback optional The collection result callback Returns:Promise if no callback passed
 
- 
    findOneAndReplace(filter, replacement, options, callback){Promise}
- 
    
    
    Find a document and replace it in one atomic operation, requires a write lock for the duration of the operation. Name Type Default Description filterobject Document selection filter. replacementobject Document replacing the matching document. optionsobject null optional Optional settings. Name Type Default Description projectionobject null optional Limits the fields to return for all matching documents. sortobject null optional Determines which document the operation modifies if the query selects multiple documents. maxTimeMSnumber null optional The maximum amount of time to allow the query to run. upsertboolean false optional Upsert the document if it does not exist. returnOriginalboolean true optional When false, returns the updated document rather than the original. The default is true. sessionClientSession optional optional session to use for this operation callbackCollection~findAndModifyCallback optional The collection result callback Returns:Promise if no callback passed
 
- 
    findOneAndUpdate(filter, update, options, callback){Promise}
- 
    
    
    Find a document and update it in one atomic operation, requires a write lock for the duration of the operation. Name Type Default Description filterobject Document selection filter. updateobject Update operations to be performed on the document optionsobject null optional Optional settings. Name Type Default Description projectionobject null optional Limits the fields to return for all matching documents. sortobject null optional Determines which document the operation modifies if the query selects multiple documents. maxTimeMSnumber null optional The maximum amount of time to allow the query to run. upsertboolean false optional Upsert the document if it does not exist. returnOriginalboolean true optional When false, returns the updated document rather than the original. The default is true. sessionClientSession optional optional session to use for this operation callbackCollection~findAndModifyCallback optional The collection result callback Returns:Promise if no callback passed
 
- 
    geoHaystackSearch(x, y, options, callback){Promise}
- 
    
    
    Execute a geo search using a geo haystack index on a collection. Name Type Default Description xnumber Point to search on the x axis, ensure the indexes are ordered in the same order. ynumber Point to search on the y axis, ensure the indexes are ordered in the same order. optionsobject null optional Optional settings. Name Type Default Description readPreferenceReadPreference | string null optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). maxDistancenumber null optional Include results up to maxDistance from the point. searchobject null optional Filter the results by a query. limitnumber false optional Max number of results to return. sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    group(keys, condition, initial, reduce, finalize, command, options, callback){Promise}
- 
    
    
    Run a group command across a collection Name Type Default Description keysobject | array | function | code An object, array or function expressing the keys to group by. conditionobject An optional condition that must be true for a row to be considered. initialobject Initial value of the aggregation counter object. reducefunction | Code The reduce function aggregates (reduces) the objects iterated finalizefunction | Code An optional function to be run on each item in the result set just before the item is returned. commandboolean Specify if you wish to run using the internal group command or using eval, default is true. optionsobject null optional Optional settings. Name Type Default Description readPreferenceReadPreference | string null optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The command result callback - Deprecated
- MongoDB 3.6 or higher will no longer support the group command. We recommend rewriting using the aggregation framework.
 
 Returns:Promise if no callback passed
 
- 
    indexes(options, callback){Promise}
- 
    
    
    Retrieve all the indexes on the collection. Name Type Description optionsObject optional Optional settings Name Type Description sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    indexExists(indexes, options, callback){Promise}
- 
    
    
    Checks if one or more indexes exist on the collection, fails on first non-existing index Name Type Description indexesstring | array One or more index names to check. optionsObject optional Optional settings Name Type Description sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    indexInformation(options, callback){Promise}
- 
    
    
    Retrieves this collections index info. Name Type Default Description optionsobject null optional Optional settings. Name Type Default Description fullboolean false optional Returns the full raw index information. sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    initializeOrderedBulkOp(options, callback){null}
- 
    
    
    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. Name Type Default Description optionsobject null optional Optional settings. Name Type Default Description wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. sessionClientSession optional optional session to use for this operation callbackOrderedBulkOperation The command result callback 
- 
    initializeUnorderedBulkOp(options){UnorderedBulkOperation}
- 
    
    
    Initiate a Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order. Name Type Default Description optionsobject null optional Optional settings. Name Type Default Description wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. sessionClientSession optional optional session to use for this operation 
- 
    insert(docs, options, callback){Promise}
- 
    
    
    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.Name Type Default Description docsobject | Array.<object> Documents to insert. optionsobject null optional Optional settings. Name Type Default Description wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. serializeFunctionsboolean false optional Serialize functions on any object. forceServerObjectIdboolean false optional Force server to assign _id values instead of driver. bypassDocumentValidationboolean false optional Allow driver to bypass schema validation in MongoDB 3.2 or higher. sessionClientSession optional optional session to use for this operation callbackCollection~insertWriteOpCallback optional The command result callback - Deprecated
- Use insertOne, insertMany or bulkWrite
 
 Returns:Promise if no callback passed
 
- 
    insertMany(docs, options, callback){Promise}
- 
    
    
    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.Name Type Default Description docsArray.<object> Documents to insert. optionsobject null optional Optional settings. Name Type Default Description wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. serializeFunctionsboolean false optional Serialize functions on any object. forceServerObjectIdboolean false optional Force server to assign _id values instead of driver. bypassDocumentValidationboolean false optional Allow driver to bypass schema validation in MongoDB 3.2 or higher. orderedboolean true optional If true, when an insert fails, don't execute the remaining writes. If false, continue with remaining inserts when one fails. sessionClientSession optional optional session to use for this operation callbackCollection~insertWriteOpCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    insertOne(doc, options, callback){Promise}
- 
    
    
    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.Name Type Default Description docobject Document to insert. optionsobject null optional Optional settings. Name Type Default Description wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. serializeFunctionsboolean false optional Serialize functions on any object. forceServerObjectIdboolean false optional Force server to assign _id values instead of driver. bypassDocumentValidationboolean false optional Allow driver to bypass schema validation in MongoDB 3.2 or higher. sessionClientSession optional optional session to use for this operation callbackCollection~insertOneWriteOpCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    isCapped(options, callback){Promise}
- 
    
    
    Returns if the collection is a capped collection Name Type Description optionsObject optional Optional settings Name Type Description sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The results callback Returns:Promise if no callback passed
 
- 
    listIndexes(options){CommandCursor}
- 
    
    
    Get the list of all indexes information for the collection. Name Type Default Description optionsobject null optional Optional settings. Name Type Default Description batchSizenumber null optional The batchSize for the returned command cursor or if pre 2.8 the systems batch collection readPreferenceReadPreference | string null optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). sessionClientSession optional optional session to use for this operation 
- 
    mapReduce(map, reduce, options, callback){Promise}
- 
    
    
    Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection. Name Type Default Description mapfunction | string The mapping function. reducefunction | string The reduce function. optionsobject null optional Optional settings. Name Type Default Description readPreferenceReadPreference | string null optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). outobject null optional Sets the output target for the map reduce job. {inline:1} | {replace:'collectionName'} | {merge:'collectionName'} | {reduce:'collectionName'} queryobject null optional Query filter object. sortobject null optional Sorts the input objects using this key. Useful for optimization, like sorting by the emit key for fewer reduces. limitnumber null optional Number of objects to return from collection. keeptempboolean false optional Keep temporary data. finalizefunction | string null optional Finalize function. scopeobject null optional Can pass in variables that can be access from map/reduce/finalize. jsModeboolean false optional It is possible to make the execution stay in JS. Provided in MongoDB > 2.0.X. verboseboolean false optional Provide statistics on job execution time. bypassDocumentValidationboolean false optional Allow driver to bypass schema validation in MongoDB 3.2 or higher. sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The command result callback Throws:Returns:Promise if no callback passed
 
- 
    options(options, callback){Promise}
- 
    
    
    Returns the options of the collection. Name Type Description optionsObject optional Optional settings Name Type Description sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The results callback Returns:Promise if no callback passed
 
- 
    parallelCollectionScan(options, callback){Promise}
- 
    
    
    Return N number of parallel cursors for a collection allowing parallel reading of entire collection. There are 
 no ordering guarantees for returned results.Name Type Default Description optionsobject null optional Optional settings. Name Type Default Description readPreferenceReadPreference | string null optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). batchSizenumber null optional Set the batchSize for the getMoreCommand when iterating over the query results. numCursorsnumber 1 optional The maximum number of parallel command cursors to return (the number of returned cursors will be in the range 1:numCursors) rawboolean false optional Return all BSON documents as Raw Buffer documents. callbackCollection~parallelCollectionScanCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    reIndex(options, callback){Promise}
- 
    
    
    Reindex all indexes on the collection 
 Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.Name Type Description optionsObject optional Optional settings Name Type Description sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    remove(selector, options, callback){Promise}
- 
    
    
    Remove documents. Name Type Default Description selectorobject The selector for the update operation. optionsobject null optional Optional settings. Name Type Default Description wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. singleboolean false optional Removes the first document found. sessionClientSession optional optional session to use for this operation callbackCollection~writeOpCallback optional The command result callback - Deprecated
- use deleteOne, deleteMany or bulkWrite
 
 Returns:Promise if no callback passed
 
- 
    rename(newName, options, callback){Promise}
- 
    
    
    Rename the collection. Name Type Default Description newNamestring New name of of the collection. optionsobject null optional Optional settings. Name Type Default Description dropTargetboolean false optional Drop the target name collection if it previously exists. sessionClientSession optional optional session to use for this operation callbackCollection~collectionResultCallback optional The results callback Returns:Promise if no callback passed
 
- 
    replaceOne(filter, doc, options, callback){Promise}
- 
    
    
    Replace a document on MongoDB Name Type Default Description filterobject The Filter used to select the document to update docobject The Document that replaces the matching document optionsobject null optional Optional settings. Name Type Default Description upsertboolean false optional Update operation is an upsert. wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. bypassDocumentValidationboolean false optional Allow driver to bypass schema validation in MongoDB 3.2 or higher. sessionClientSession optional optional session to use for this operation callbackCollection~updateWriteOpCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    save(doc, options, callback){Promise}
- 
    
    
    Save a document. Simple full document replacement function. Not recommended for efficiency, use atomic 
 operators and update instead for more efficient operations.Name Type Default Description docobject Document to save optionsobject null optional Optional settings. Name Type Default Description wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. sessionClientSession optional optional session to use for this operation callbackCollection~writeOpCallback optional The command result callback - Deprecated
- use insertOne, insertMany, updateOne or updateMany
 
 Returns:Promise if no callback passed
 
- 
    stats(options, callback){Promise}
- 
    
    
    Get all the collection statistics. Name Type Default Description optionsobject null optional Optional settings. Name Type Default Description scalenumber null optional Divide the returned sizes by scale value. sessionClientSession optional optional session to use for this operation callbackCollection~resultCallback optional The collection result callback Returns:Promise if no callback passed
 
- 
    update(selector, document, options, callback){Promise}
- 
    
    
    Updates documents. Name Type Default Description selectorobject The selector for the update operation. documentobject The update document. optionsobject null optional Optional settings. Name Type Default Description wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. upsertboolean false optional Update operation is an upsert. multiboolean false optional Update one/all documents with operation. bypassDocumentValidationboolean false optional Allow driver to bypass schema validation in MongoDB 3.2 or higher. collationobject null optional Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields). arrayFiltersArray null optional optional list of array filters referenced in filtered positional operators sessionClientSession optional optional session to use for this operation callbackCollection~writeOpCallback optional The command result callback - Deprecated
- use updateOne, updateMany or bulkWrite
 
 Throws:Returns:Promise if no callback passed
 
- 
    updateMany(filter, update, options, callback){Promise}
- 
    
    
    Update multiple documents on MongoDB Name Type Default Description filterobject The Filter used to select the documents to update updateobject The update operations to be applied to the document optionsobject null optional Optional settings. Name Type Default Description upsertboolean false optional Update operation is an upsert. wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. arrayFiltersArray null optional optional list of array filters referenced in filtered positional operators sessionClientSession optional optional session to use for this operation callbackCollection~updateWriteOpCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    updateOne(filter, update, options, callback){Promise}
- 
    
    
    Update a single document on MongoDB Name Type Default Description filterobject The Filter used to select the document to update updateobject The update operations to be applied to the document optionsobject null optional Optional settings. Name Type Default Description upsertboolean false optional Update operation is an upsert. wnumber | string null optional The write concern. wtimeoutnumber null optional The write concern timeout. jboolean false optional Specify a journal write concern. bypassDocumentValidationboolean false optional Allow driver to bypass schema validation in MongoDB 3.2 or higher. arrayFiltersArray null optional optional list of array filters referenced in filtered positional operators sessionClientSession optional optional session to use for this operation callbackCollection~updateWriteOpCallback optional The command result callback Returns:Promise if no callback passed
 
- 
    watch(pipeline, options){ChangeStream}
- 
    
    
    Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this collection. Name Type Default Description pipelineArray null optional 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. optionsobject null optional Optional settings Name Type Default Description fullDocumentstring 'default' optional Allowed values: ‘default’, ‘updateLookup’. When set to ‘updateLookup’, the change stream will include both a delta describing the changes to the document, as well as a copy of the entire document that was changed from some time after the change occurred. resumeAfterobject null optional Specifies the logical starting point for the new change stream. This should be the _id field from a previously returned change stream document. maxAwaitTimeMSnumber optional The maximum amount of time for the server to wait on new documents to satisfy a change stream query batchSizenumber null optional The number of documents to return per batch. See aggregation documentation. collationobject null optional Specify collation settings for operation. See aggregation documentation. readPreferenceReadPreference null optional The read preference. Defaults to the read preference of the database or collection. See read preference documentation. sessionClientSession optional optional session to use for this operation - Since:
- 3.0.0
 
 Returns:ChangeStream instance.
 
Type Definitions
- 
    aggregationCallback(error, cursor)
- 
    
    
    The callback format for an aggregation call Name Type Description errorMongoError An error instance representing the error during the execution. cursorAggregationCursor The cursor if the aggregation command was executed successfully. 
- 
    bulkWriteOpCallback(error, result)
- 
    
    
    The callback format for inserts Name Type Description errorBulkWriteError An error instance representing the error during the execution. resultCollection~BulkWriteOpResult The result object if the command was executed successfully. 
- 
    BulkWriteOpResultObject
- 
    
    
    
Properties:Name Type Description insertedCountnumber Number of documents inserted. matchedCountnumber Number of documents matched for update. modifiedCountnumber Number of documents modified. deletedCountnumber Number of documents deleted. upsertedCountnumber Number of documents upserted. insertedIdsobject Inserted document generated Id's, hash key is the index of the originating operation upsertedIdsobject Upserted document generated Id's, hash key is the index of the originating operation resultobject The command result object. 
- 
    collectionResultCallback(error, collection)
- 
    
    
    The callback format for the collection method, must be used if strict is specified Name Type Description errorMongoError An error instance representing the error during the execution. collectionCollection The collection instance. 
- 
    countCallback(error, result)
- 
    
    
    The callback format for results Name Type Description errorMongoError An error instance representing the error during the execution. resultnumber The count of documents that matched the query. 
- 
    deleteWriteOpCallback(error, result)
- 
    
    
    The callback format for inserts Name Type Description errorMongoError An error instance representing the error during the execution. resultCollection~deleteWriteOpResult The result object if the command was executed successfully. 
- 
    deleteWriteOpResultObject
- 
    
    
    
Properties:Name Type Description resultObject The raw result returned from MongoDB, field will vary depending on server version. PropertiesName Type Description okNumber Is 1 if the command executed correctly. nNumber The total count of documents deleted. connectionObject The connection object used for the operation. deletedCountNumber The number of documents deleted. 
- 
    findAndModifyCallback(error, result)
- 
    
    
    The callback format for inserts Name Type Description errorMongoError An error instance representing the error during the execution. resultCollection~findAndModifyWriteOpResult The result object if the command was executed successfully. 
- 
    findAndModifyWriteOpResultObject
- 
    
    
    
Properties:Name Type Description valueobject Document returned from findAndModify command. lastErrorObjectobject The raw lastErrorObject returned from the command. okNumber Is 1 if the command executed correctly. 
- 
    insertOneWriteOpCallback(error, result)
- 
    
    
    The callback format for inserts Name Type Description errorMongoError An error instance representing the error during the execution. resultCollection~insertOneWriteOpResult The result object if the command was executed successfully. 
- 
    insertOneWriteOpResultObject
- 
    
    
    
Properties:Name Type Description insertedCountNumber The total amount of documents inserted. opsArray.<object> All the documents inserted using insertOne/insertMany/replaceOne. Documents contain the _id field if forceServerObjectId == false for insertOne/insertMany insertedIdObjectId The driver generated ObjectId for the insert operation. connectionobject The connection object used for the operation. resultobject The raw command result object returned from MongoDB (content might vary by server version). PropertiesName Type Description okNumber Is 1 if the command executed correctly. nNumber The total count of documents inserted. 
- 
    insertWriteOpCallback(error, result)
- 
    
    
    The callback format for inserts Name Type Description errorMongoError An error instance representing the error during the execution. resultCollection~insertWriteOpResult The result object if the command was executed successfully. 
- 
    insertWriteOpResultObject
- 
    
    
    
Properties:Name Type Description insertedCountNumber The total amount of documents inserted. opsArray.<object> All the documents inserted using insertOne/insertMany/replaceOne. Documents contain the _id field if forceServerObjectId == false for insertOne/insertMany insertedIdsObject.<Number, ObjectId> Map of the index of the inserted document to the id of the inserted document. connectionobject The connection object used for the operation. resultobject The raw command result object returned from MongoDB (content might vary by server version). PropertiesName Type Description okNumber Is 1 if the command executed correctly. nNumber The total count of documents inserted. 
- 
    parallelCollectionScanCallback(error, cursors)
- 
    
    
    The callback format for results Name Type Description errorMongoError An error instance representing the error during the execution. cursorsArray.<Cursor> A list of cursors returned allowing for parallel reading of collection. 
- 
    resultCallback(error, result)
- 
    
    
    The callback format for results Name Type Description errorMongoError An error instance representing the error during the execution. resultobject The result object if the command was executed successfully. 
- 
    updateWriteOpCallback(error, result)
- 
    
    
    The callback format for inserts Name Type Description errorMongoError An error instance representing the error during the execution. resultCollection~updateWriteOpResult The result object if the command was executed successfully. 
- 
    updateWriteOpResultObject
- 
    
    
    
Properties:Name Type Description resultObject The raw result returned from MongoDB, field will vary depending on server version. PropertiesName Type Description okNumber Is 1 if the command executed correctly. nNumber The total count of documents scanned. nModifiedNumber The total count of documents modified. connectionObject The connection object used for the operation. matchedCountNumber The number of documents that matched the filter. modifiedCountNumber The number of documents that were modified. upsertedCountNumber The number of documents upserted. upsertedIdObject The upserted id. PropertiesName Type Description _idObjectId The upserted _id returned from the server. 
- 
    writeOpCallback(error, result)
- 
    
    
    The callback format for inserts Name Type Description errorMongoError An error instance representing the error during the execution. resultCollection~WriteOpResult The result object if the command was executed successfully. 
- 
    WriteOpResultObject
- 
    
    
    
Properties:Name Type Description opsArray.<object> All the documents inserted using insertOne/insertMany/replaceOne. Documents contain the _id field if forceServerObjectId == false for insertOne/insertMany connectionobject The connection object used for the operation. resultobject The command result object.