new Collection()
Create a new Collection instance (INTERNAL TYPE, do not instantiate directly)
Members
-
readonlycollectionNamestring
-
The name of this collection
-
readonlydbNamestring
-
The name of the database this collection belongs to
-
hintobject
-
The current index hint for the collection
-
readonlynamespacestring
-
The namespace of this collection, in the format
${this.dbName}.${this.collectionName} -
readonlyreadConcernReadConcern
-
The current readConcern of the collection. If not explicitly defined for
this collection, will be inherited from the parent DB -
readonlyreadPreferenceReadPreference
-
The current readPreference of the collection. If not explicitly defined for
this collection, will be inherited from the parent DB -
readonlywriteConcernWriteConcern
-
The current writeConcern of the collection. If not explicitly defined for
this collection, will be inherited from the parent DB
Methods
-
aggregate(pipeline, options, callback){null|AggregationCursor}
-
Execute an aggregation framework pipeline against the collection, needs MongoDB >= 2.2
Name Type Default Description pipelineobject [] optional Array containing all the aggregation framework commands for the execution.
optionsobject optional Optional settings.
Name Type Default Description readPreferenceReadPreference | string optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
batchSizenumber 1000 optional The number of documents to return per batch. See aggregation documentation.
cursorobject 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 1000 optional Deprecated. Use
options.batchSizeexplainboolean 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 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.
maxAwaitTimeMSnumber optional The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query.
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 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
hintstring | object optional Add an index selection hint 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 } }
{ 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}}
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 Description operationsArray.<object> Bulk operations to perform.
optionsobject optional Optional settings.
Name Type Default Description 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.
arrayFiltersArray.<object> optional Determines which array elements to modify for update operation in MongoDB 3.6 or higher.
wnumber | string optional The write concern.
wtimeoutnumber optional The write concern timeout.
jboolean false optional Specify a journal write concern.
checkKeysboolean false optional If true, will throw if bson documents start with
$or include a.in any key valueserializeFunctionsboolean false optional Serialize functions on any object.
ignoreUndefinedboolean false optional Specify if the BSON serializer should ignore undefined fields.
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}
-
An estimated count of matching documents in the db to a query.
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, usecountDocuments.
To obtain an estimated count of all documents in the collection, useestimatedDocumentCount.Name Type Default Description queryobject {} optional The query for the count.
optionsobject optional Optional settings.
Name Type Description collationobject optional Specify collation settings for operation. See aggregation documentation.
limitboolean optional The limit of documents to count.
skipboolean optional The number of documents to skip for the count.
hintstring optional An index name hint for the query.
readPreferenceReadPreference | string optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
maxTimeMSnumber optional Number of milliseconds to wait before aborting the query.
sessionClientSession optional optional session to use for this operation
callbackCollection~countCallback optional The command result callback
- Deprecated
- use
countDocumentsorestimatedDocumentCountinstead
- use
Returns:
Promise if no callback passed
-
countDocuments(query, options, callback){Promise}
-
Gets the number of documents matching the filter.
For a fast count of the total documents in a collection seeestimatedDocumentCount.
Note: When migrating fromcounttocountDocuments
the following query operators must be replaced:Operator Replacement $where$expr$near$geoWithinwith$center$nearSphere$geoWithinwith$centerSphereName Type Description queryobject optional the query for the count
optionsobject optional Optional settings.
Name Type Description collationobject optional Specifies a collation.
hintstring | object optional The index to use.
limitnumber optional The maximum number of document to count.
maxTimeMSnumber optional The maximum amount of time to allow the operation to run.
skipnumber optional The number of documents to skip before counting.
callbackCollection~countCallback optional The command result callback.
- See:
-
- https://www.mongodb.com/docs/manual/reference/operator/query/expr/
- https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/
- https://www.mongodb.com/docs/manual/reference/operator/query/center/#op._S_center
- https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/#op._S_centerSphere
Returns:
Promise if no callback passed.
-
createIndex(fieldOrSpec, options, callback){Promise}
-
Creates an index on the db and collection collection.
Name Type Description fieldOrSpecstring | array | object Defines the index.
optionsobject optional Optional settings.
Name Type Default Description wnumber | string optional The write concern.
wtimeoutnumber 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 optional For geospatial indexes set the lower bound for the co-ordinates.
maxnumber optional For geospatial indexes set the high bound for the co-ordinates.
vnumber optional Specify the format version of the indexes.
expireAfterSecondsnumber optional Allows you to expire data on indexes applied to a data (MongoDB 2.2 or higher)
namestring optional Override the autogenerated index name (useful if the resulting name is larger than 128 bytes)
partialFilterExpressionobject optional Creates a partial index based on the given filter object (MongoDB 3.2 or higher)
collationobject 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
Example
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' }]) -
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.Note: Unlike
createIndex, this function takes in raw index specifications.
Index specifications are defined here.Name Type Description indexSpecsArray.<Collection~IndexDefinition> 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
Example
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'
}
]); -
deleteMany(filter, options, callback){Promise}
-
Delete multiple documents from a collection
Name Type Description filterobject The Filter used to select the documents to remove
optionsobject optional Optional settings.
Name Type Default Description collationobject optional Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
wnumber | string optional The write concern.
wtimeoutnumber optional The write concern timeout.
jboolean false optional Specify a journal write concern.
checkKeysboolean false optional If true, will throw if bson documents start with
$or include a.in any key valueserializeFunctionsboolean false optional Serialize functions on any object.
ignoreUndefinedboolean false optional Specify if the BSON serializer should ignore undefined fields.
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 from a collection
Name Type Description filterobject The Filter used to select the document to remove
optionsobject optional Optional settings.
Name Type Default Description collationobject optional Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
wnumber | string optional The write concern.
wtimeoutnumber optional The write concern timeout.
jboolean false optional Specify a journal write concern.
checkKeysboolean false optional If true, will throw if bson documents start with
$or include a.in any key valueserializeFunctionsboolean false optional Serialize functions on any object.
ignoreUndefinedboolean false optional Specify if the BSON serializer should ignore undefined fields.
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 a list of distinct values for the given key across a collection.
Name Type Description keystring Field of the document to find distinct values for.
queryobject optional The query for filtering the set of documents to which we apply the distinct filter.
optionsobject optional Optional settings.
Name Type Description readPreferenceReadPreference | string optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
maxTimeMSnumber optional Number of milliseconds to wait before aborting the query.
collationobject optional Specify collation settings for operation. See aggregation documentation.
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 Description optionsobject optional Optional settings.
Name Type Description writeConcernWriteConcern optional A full WriteConcern object
wnumber | string optional The write concern
wtimeoutnumber optional The write concern timeout
jboolean optional The journal write concern
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 Description indexNamestring Name of the index to drop.
optionsobject optional Optional settings.
Name Type Default Description wnumber | string optional The write concern.
wtimeoutnumber 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 milliseconds 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 milliseconds 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 Description fieldOrSpecstring | object Defines the index.
optionsobject optional Optional settings.
Name Type Default Description wnumber | string optional The write concern.
wtimeoutnumber 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 optional For geospatial indexes set the lower bound for the co-ordinates.
maxnumber optional For geospatial indexes set the high bound for the co-ordinates.
vnumber optional Specify the format version of the indexes.
expireAfterSecondsnumber optional Allows you to expire data on indexes applied to a data (MongoDB 2.2 or higher)
namenumber optional Override the autogenerated index name (useful if the resulting name is larger than 128 bytes)
collationobject 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
-
estimatedDocumentCount(options, callback){Promise}
-
Gets an estimate of the count of documents in a collection using collection metadata.
Name Type Description optionsobject optional Optional settings.
Name Type Description maxTimeMSnumber optional The maximum amount of time to allow the operation to run.
callbackCollection~countCallback optional The command result callback.
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 optional Optional settings.
Name Type Default Description limitnumber 0 optional Sets the limit of documents returned in the query.
sortarray | object optional Set to sort the documents coming back from the query. Array of indexes, [['a', 1]] etc.
projectionobject optional The fields to return in the query. Object of fields to either include or exclude (one of, not both), {'a':1, 'b': 1} or {'a': 0, 'b': 0}
fieldsobject optional Deprecated Use
options.projectioninsteadskipnumber 0 optional Set to skip N documents ahead in your query (useful for pagination).
hintObject 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 DEPRECATED: Snapshot query.
timeoutboolean false optional Specify if the cursor can timeout.
tailableboolean false optional Specify if the cursor is tailable.
awaitDataboolean false optional Specify if the cursor is a a tailable-await cursor. Requires
tailableto be truebatchSizenumber 1000 optional Set the batchSize for the getMoreCommand when iterating over the query results.
returnKeyboolean false optional Only return the index key.
maxScannumber optional DEPRECATED: Limit the number of items to scan.
minnumber optional Set index bounds.
maxnumber optional Set index bounds.
showDiskLocboolean false optional Show disk location of results.
commentstring 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 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 optional Number of milliseconds to wait before aborting the query.
maxAwaitTimeMSnumber optional The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. Requires
taiableandawaitDatato be truenoCursorTimeoutboolean optional The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. Set this option to prevent that.
collationobject 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 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 optional Optional settings.
Name Type Default Description wnumber | string optional The write concern.
wtimeoutnumber 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 optional Object containing the field projection for the result returned from the operation.
fieldsobject optional Deprecated Use
options.projectioninsteadsessionClientSession optional optional session to use for this operation
arrayFiltersArray optional optional list of array filters referenced in filtered positional operators
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 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 optional Optional settings.
Name Type Default Description wnumber | string optional The write concern.
wtimeoutnumber 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 Description queryobject Query for find Operation
optionsobject optional Optional settings.
Name Type Default Description limitnumber 0 optional Sets the limit of documents returned in the query.
sortarray | object optional Set to sort the documents coming back from the query. Array of indexes, [['a', 1]] etc.
projectionobject optional The fields to return in the query. Object of fields to include or exclude (not both), {'a':1}
fieldsobject optional Deprecated Use
options.projectioninsteadskipnumber 0 optional Set to skip N documents ahead in your query (useful for pagination).
hintObject 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 DEPRECATED: Snapshot query.
timeoutboolean false optional Specify if the cursor can timeout.
tailableboolean false optional Specify if the cursor is tailable.
batchSizenumber 1 optional Set the batchSize for the getMoreCommand when iterating over the query results.
returnKeyboolean false optional Only return the index key.
maxScannumber optional DEPRECATED: Limit the number of items to scan.
minnumber optional Set index bounds.
maxnumber optional Set index bounds.
showDiskLocboolean false optional Show disk location of results.
commentstring 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 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 optional Number of milliseconds to wait before aborting the query.
collationobject 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.<Collection~findAndModifyWriteOpResultObject>}
-
Find a document and delete it in one atomic operation. Requires a write lock for the duration of the operation.
Name Type Description filterobject The Filter used to select the document to remove
optionsobject optional Optional settings.
Name Type Default Description collationobject optional Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
projectionobject optional Limits the fields to return for all matching documents.
sortobject optional Determines which document the operation modifies if the query selects multiple documents.
maxTimeMSnumber optional The maximum amount of time to allow the query to run.
checkKeysboolean false optional If true, will throw if bson documents start with
$or include a.in any key valueserializeFunctionsboolean false optional Serialize functions on any object.
ignoreUndefinedboolean false optional Specify if the BSON serializer should ignore undefined fields.
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.<Collection~findAndModifyWriteOpResultObject>}
-
Find a document and replace it in one atomic operation. Requires a write lock for the duration of the operation.
Name Type Description filterobject The Filter used to select the document to replace
replacementobject The Document that replaces the matching document
optionsobject optional Optional settings.
Name Type Default Description bypassDocumentValidationboolean false optional Allow driver to bypass schema validation in MongoDB 3.2 or higher.
collationobject optional Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
maxTimeMSnumber optional The maximum amount of time to allow the query to run.
projectionobject optional Limits the fields to return for all matching documents.
sortobject optional Determines which document the operation modifies if the query selects multiple documents.
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.
checkKeysboolean false optional If true, will throw if bson documents start with
$or include a.in any key valueserializeFunctionsboolean false optional Serialize functions on any object.
ignoreUndefinedboolean false optional Specify if the BSON serializer should ignore undefined fields.
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.<Collection~findAndModifyWriteOpResultObject>}
-
Find a document and update it in one atomic operation. Requires a write lock for the duration of the operation.
Name Type Description filterobject The Filter used to select the document to update
updateobject Update operations to be performed on the document
optionsobject optional Optional settings.
Name Type Default Description arrayFiltersArray optional optional list of array filters referenced in filtered positional operators
bypassDocumentValidationboolean false optional Allow driver to bypass schema validation in MongoDB 3.2 or higher.
collationobject optional Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
maxTimeMSnumber optional The maximum amount of time to allow the query to run.
projectionobject optional Limits the fields to return for all matching documents.
sortobject optional Determines which document the operation modifies if the query selects multiple documents.
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.
checkKeysboolean false optional If true, will throw if bson documents start with
$or include a.in any key valueserializeFunctionsboolean false optional Serialize functions on any object.
ignoreUndefinedboolean false optional Specify if the BSON serializer should ignore undefined fields.
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 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 optional Optional settings.
Name Type Default Description readPreferenceReadPreference | string optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
maxDistancenumber optional Include results up to maxDistance from the point.
searchobject 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 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 optional Optional settings.
Name Type Description readPreferenceReadPreference | string 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 no longer supports 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 Description optionsobject 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 Description optionsobject optional Optional settings.
Name Type Default Description wnumber | string optional The write concern.
wtimeoutnumber optional The write concern timeout.
jboolean false optional Specify a journal write concern.
sessionClientSession optional optional session to use for this operation
ignoreUndefinedboolean false optional Specify if the BSON serializer should ignore undefined fields.
callbackOrderedBulkOperation The command result callback
-
initializeUnorderedBulkOp(options){UnorderedBulkOperation}
-
Initiate an Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order.
Name Type Description optionsobject optional Optional settings.
Name Type Default Description wnumber | string optional The write concern.
wtimeoutnumber optional The write concern timeout.
jboolean false optional Specify a journal write concern.
ignoreUndefinedboolean false optional Specify if the BSON serializer should ignore undefined fields.
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 Description docsobject | Array.<object> Documents to insert.
optionsobject optional Optional settings.
Name Type Default Description wnumber | string optional The write concern.
wtimeoutnumber 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 Description docsArray.<object> Documents to insert.
optionsobject optional Optional settings.
Name Type Default Description 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.
forceServerObjectIdboolean false optional Force server to assign _id values instead of driver.
wnumber | string optional The write concern.
wtimeoutnumber optional The write concern timeout.
jboolean false optional Specify a journal write concern.
checkKeysboolean true optional If true, will throw if bson documents start with
$or include a.in any key valueserializeFunctionsboolean false optional Serialize functions on any object.
ignoreUndefinedboolean false optional Specify if the BSON serializer should ignore undefined fields.
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 Description docobject Document to insert.
optionsobject optional Optional settings.
Name Type Default Description bypassDocumentValidationboolean false optional Allow driver to bypass schema validation in MongoDB 3.2 or higher.
forceServerObjectIdboolean false optional Force server to assign _id values instead of driver.
wnumber | string optional The write concern.
wtimeoutnumber optional The write concern timeout.
jboolean false optional Specify a journal write concern.
checkKeysboolean true optional If true, will throw if bson documents start with
$or include a.in any key valueserializeFunctionsboolean false optional Serialize functions on any object.
ignoreUndefinedboolean false optional Specify if the BSON serializer should ignore undefined fields.
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 Description optionsobject optional Optional settings.
Name Type Default Description batchSizenumber 1000 optional The batchSize for the returned command cursor or if pre 2.8 the systems batch collection
readPreferenceReadPreference | string 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 Description mapfunction | string The mapping function.
reducefunction | string The reduce function.
optionsobject optional Optional settings.
Name Type Default Description readPreferenceReadPreference | string optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
outobject optional Sets the output target for the map reduce job. {inline:1} | {replace:'collectionName'} | {merge:'collectionName'} | {reduce:'collectionName'}
queryobject optional Query filter object.
sortobject optional Sorts the input objects using this key. Useful for optimization, like sorting by the emit key for fewer reduces.
limitnumber optional Number of objects to return from collection.
keeptempboolean false optional Keep temporary data.
finalizefunction | string optional Finalize function.
scopeobject 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 Description optionsobject optional Optional settings.
Name Type Default Description readPreferenceReadPreference | string optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
batchSizenumber 1000 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 Description selectorobject The selector for the update operation.
optionsobject optional Optional settings.
Name Type Default Description collationobject optional Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
wnumber | string optional The write concern.
wtimeoutnumber 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 Description newNamestring New name of of the collection.
optionsobject 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.<Collection~updateWriteOpResult>}
-
Replace a document in a collection with another document
Name Type Description filterobject The Filter used to select the document to replace
docobject The Document that replaces the matching document
optionsobject optional Optional settings.
Name Type Default Description bypassDocumentValidationboolean false optional Allow driver to bypass schema validation in MongoDB 3.2 or higher.
collationobject optional Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
hintobject optional An optional hint for query optimization. See the update command reference for more information.
upsertboolean false optional When true, creates a new document if no document matches the query.
wnumber | string optional The write concern.
wtimeoutnumber optional The write concern timeout.
jboolean false optional Specify a journal write concern.
checkKeysboolean false optional If true, will throw if bson documents start with
$or include a.in any key valueserializeFunctionsboolean false optional Serialize functions on any object.
ignoreUndefinedboolean false optional Specify if the BSON serializer should ignore undefined fields.
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 Description docobject Document to save
optionsobject optional Optional settings.
Name Type Default Description wnumber | string optional The write concern.
wtimeoutnumber 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 Description optionsobject optional Optional settings.
Name Type Description scalenumber 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, update, options, callback){Promise}
-
Updates documents.
Name Type Description selectorobject The selector for the update operation.
updateobject The update operations to be applied to the documents
optionsobject optional Optional settings.
Name Type Default Description wnumber | string optional The write concern.
wtimeoutnumber 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 optional Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
arrayFiltersArray optional optional list of array filters referenced in filtered positional operators
sessionClientSession optional optional session to use for this operation
hintobject optional An optional hint for query optimization. See the update command reference for more information.
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.<Collection~updateWriteOpResult>}
-
Update multiple documents in a collection
Name Type Description filterobject The Filter used to select the documents to update
updateobject The update operations to be applied to the documents
optionsobject optional Optional settings.
Name Type Default Description arrayFiltersArray optional optional list of array filters referenced in filtered positional operators
bypassDocumentValidationboolean false optional Allow driver to bypass schema validation in MongoDB 3.2 or higher.
collationobject optional Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
hintobject optional An optional hint for query optimization. See the update command reference for more information.
upsertboolean false optional When true, creates a new document if no document matches the query..
wnumber | string optional The write concern.
wtimeoutnumber optional The write concern timeout.
jboolean false optional Specify a journal write concern.
checkKeysboolean false optional If true, will throw if bson documents start with
$or include a.in any key valueserializeFunctionsboolean false optional Serialize functions on any object.
ignoreUndefinedboolean false optional Specify if the BSON serializer should ignore undefined fields.
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 in a collection
Name Type Description filterobject The Filter used to select the document to update
updateobject The update operations to be applied to the document
optionsobject optional Optional settings.
Name Type Default Description arrayFiltersArray optional optional list of array filters referenced in filtered positional operators
bypassDocumentValidationboolean false optional Allow driver to bypass schema validation in MongoDB 3.2 or higher.
collationobject optional Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
hintobject optional An optional hint for query optimization. See the update command reference for more information.
upsertboolean false optional When true, creates a new document if no document matches the query..
wnumber | string optional The write concern.
wtimeoutnumber optional The write concern timeout.
jboolean false optional Specify a journal write concern.
checkKeysboolean false optional If true, will throw if bson documents start with
$or include a.in any key valueserializeFunctionsboolean false optional Serialize functions on any object.
ignoreUndefinedboolean false optional Specify if the BSON serializer should ignore undefined fields.
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 Description pipelineArray 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 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 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 1000 optional The number of documents to return per batch. See aggregation documentation.
collationobject optional Specify collation settings for operation. See aggregation documentation.
readPreferenceReadPreference optional The read preference. Defaults to the read preference of the database or collection. See read preference documentation.
startAtOperationTimeTimestamp optional receive change events that occur after the specified timestamp
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 deletes
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. Will vary depending on server version.
Properties
Name 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 the
findAndModifycommand. If no documents were found,valuewill benullby default (returnOriginal: true), even if a document was upserted; ifreturnOriginalwas false, the upserted document will be returned in that case.lastErrorObjectobject The raw lastErrorObject returned from the command. See findAndModify command documentation.
okNumber Is 1 if the command executed correctly.
-
IndexDefinitionobject
-
A definition for an index. Used by the createIndex command.
-
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).
Properties
Name 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).
Properties
Name 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 Argument Description resultObject The raw result returned from MongoDB. Will vary depending on server version.
Properties
Name 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.
Properties
Name Type Description _idObjectId The upserted _id returned from the server.
messageObject The raw msg response wrapped in an internal class
opsArray.<object> <optional>
In a response to
replaceOne, contains the new value of the document on the server. This is the same document that was originally passed in, and is only here for legacy purposes. -
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.