OptionalauthdbOptionalauthorizedOptionalbatchThe batchSize for the returned command cursor or if pre 2.8 the systems batch collection
Optionalbsonreturn BSON regular expressions as BSONRegExp instances.
Optionalcheckthe serializer will check if keys are valid.
OptionalcollationCollation
OptionalcommentComment to apply to the operation.
In server versions pre-4.4, 'comment' must be string. A server error will be thrown if any other type is provided.
In server versions 4.4 and above, 'comment' can be any valid BSON type.
OptionaldbOptionalenableEnable utf8 validation when deserializing BSON documents. Defaults to true.
OptionalexplainSpecifies the verbosity mode for the explain output.
Optionalfieldsallow to specify if there what fields we wish to return as unserialized raw buffer.
Optionalignoreserialize will not emit undefined fields
note that the driver sets this to false
OptionalmaxmaxTimeMS is a server-side time limit in milliseconds for processing an operation.
OptionalnameSince 4.0: If true, will only return the collection name in the response, and will omit additional info
OptionalnoOptionalomitOptionalpromotewhen deserializing a Binary will return it as a node.js Buffer instance.
Optionalpromotewhen deserializing a Long will fit it into a Number if it's smaller than 53 bits.
Optionalpromotewhen deserializing will promote BSON values to their Node.js closest equivalent types.
OptionalrawEnabling the raw option will return a Node.js Buffer which is allocated using allocUnsafe API. See this section from the Node.js Docs here for more detail about what "unsafe" refers to in this context. If you need to maintain your own editable clone of the bytes returned for an extended life time of the process, it is recommended you allocate your own buffer and clone the contents:
const raw = await collection.findOne({}, { raw: true });
const myBuffer = Buffer.alloc(raw.byteLength);
myBuffer.set(raw, 0);
// Only save and use `myBuffer` beyond this point
Please note there is a known limitation where this option cannot be used at the MongoClient level (see NODE-3946).
It does correctly work at Db, Collection, and per operation the same as other BSON options work.
OptionalreadSpecify a read concern and level for the collection. (only MongoDB 3.2 or higher supported)
OptionalreadThe preferred read preference (ReadPreference.primary, ReadPreference.primary_preferred, ReadPreference.secondary, ReadPreference.secondary_preferred, ReadPreference.nearest).
OptionalretryShould retry failed writes
Optionalserializeserialize the javascript functions
OptionalsessionSpecify ClientSession for this command
Optional ExperimentalsignalWhen provided, the corresponding AbortController can be used to abort an asynchronous action.
The signal.reason value is used as the error thrown.
NOTE: If an abort signal aborts an operation while the driver is writing to the underlying socket or reading the response from the server, the socket will be closed. If signals are aborted at a high rate during socket read/writes this can lead to a high rate of connection reestablishment.
We plan to mitigate this in a future release, please follow NODE-6062 (timeoutMS expiration suffers the same limitation).
AbortSignals are likely a best fit for human interactive interruption (ex. ctrl-C) where the frequency of cancellation is reasonably low. If a signal is programmatically aborted for 100s of operations you can empty the driver's connection pool.
const controller = new AbortController();
const { signal } = controller;
process.on('SIGINT', () => controller.abort(new Error('^C pressed')));
try {
const res = await fetch('...', { signal });
await collection.findOne(await res.json(), { signal });
catch (error) {
if (error === signal.reason) {
// signal abort error handling
}
}
Optional ExperimentaltimeoutMSSpecifies the time an operation will run until it throws a timeout error
Optionalusewhen deserializing a Long return as a BigInt.
Optionalwill
Since 4.0: If true and nameOnly is true, allows a user without the required privilege (i.e. listCollections action on the database) to run the command when access control is enforced.