MONGOC_COLLECT...MAND_WITH_OPTS(3)
π
mongoc_collection_read_write_command_with_opts π
okay bestie, welcome to the MONGOC_COLLECT...MAND_WITH_OPTS(3) page from the libmongoc manual. This one is about a command function that handles both read-y and write-y stuff, and it has one iconically useless parameter, so stay with me. π«Ά
β¨ SYNOPSIS β¨
bool
mongoc_collection_read_write_command_with_opts (
mongoc_collection_t *collection,
const bson_t *command,
const mongoc_read_prefs_t *read_prefs /* UNUSED */,
const bson_t *opts,
bson_t *reply,
bson_error_t *error);
πΈ DESCRIPTION πΈ
So what does it do? It executes a command on the server, applying the special logic for commands that both read and write, and it takes the MongoDB server version into account. If you wanna send a raw command to the server without any of this logic, use mongoc_collection_command_simple() instead.
Use this function for commands that both read and write, such as "mapReduce" with an output collection. Yes, that exact vibe.
Read and write concern and collation can be overridden by various sources. In a transaction, read concern and write concern are prohibited in opts β like, do not put them there. The highest-priority sources for these options are listed first. Read preferences are not applied. The write concern is omitted for MongoDB before 3.4.
Read Concern priority, highest first
opts- Transaction
- collection
Write Concern priority, highest first
opts- Transaction
- collection
Collation priority, highest first
opts
That's the only collation source shown in the original table, bestie.
See the example for transactions and for the "distinct" command with opts.
reply is always initialized, and must be freed with bson_destroy().
π¨ bug-note realness: themongoc_read_prefs_tparameter was included by mistake when this function was introduced in libmongoc1.5. A command that writes must not obey a read preference. Soread_prefsis ignored. Not me being dramatic; that's literally the note. π
π PARAMETERS π
collectionβ Amongoc_collection_t.commandβ Abson_tcontaining the command specification.read_prefsβ Ignored.optsβ Abson_tcontaining additional options.replyβ A maybe-NULLpointer to overwritable storage for abson_tto contain the results.errorβ An optional location for abson_error_torNULL.
opts may be NULL or a BSON document with additional command options:
readConcernβ Construct amongoc_read_concern_tand usemongoc_read_concern_append()to add the read concern toopts. Peep the example code formongoc_client_read_command_with_opts(). Read concern requires MongoDB3.2or later, otherwise an error is returned.writeConcernβ Construct amongoc_write_concern_tand usemongoc_write_concern_append()to add the write concern toopts. Peep the example code formongoc_client_write_command_with_opts().sessionIdβ First, construct amongoc_client_session_twithmongoc_client_start_session(). You can begin a transaction withmongoc_client_session_start_transaction(), optionally with amongoc_transaction_opt_tthat overrides the options inherited fromcollection, and usemongoc_client_session_append()to add the session toopts. Peep the example code formongoc_client_session_t.collationβ Configure textual comparisons. See Setting Collation Order, and the MongoDB Manual entry on Collation. Collation requires MongoDB3.2or later, otherwise an error is returned.serverIdβ To target a specific server, include anint32"serverId"field. Obtain the id by callingmongoc_client_select_server(), thenmongoc_server_description_id()on its return value.
Consult the MongoDB Manual entry on Database Commands for each command's arguments. iykyk. π
π ERRORS π
Errors are propagated via the error parameter. That's the whole section, bestie.
π«Ά RETURNS π«Ά
Returns true if successful. Returns false and sets error if there are invalid arguments or a server or network error.
A write concern timeout or write concern error is considered a failure. periodt. π
π EXAMPLE π
See the example code for mongoc_client_read_command_with_opts().
π AUTHOR π
MongoDB, Inc
π COPYRIGHT π
2009-present, MongoDB, Inc.
okay that's the page! mwah π this libmongoc manual page is version 2.5.6, dated Oct 09, 202 β the source footer got cut off mid-year, so we're not gonna invent the rest, no cap. bye bestie! π¦β¨
π¦ where this page comes from
- epel 10: mongo-c-driver-devel 2.5.6-1.el10_3 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms