MONGOC_DATABAS...MAND_WITH_OPTS(3)
π
MONGOC_DATABAS...MAND_WITH_OPTS(3) π
Okay so bestie, welcome to the libmongoc page for MONGOC_DATABAS...MAND_WITH_OPTS(3) β yes, the manual name is literally truncated like that, itβs giving mysterious main character energy. Weβre learning the read-write command function, and itβs honestly iconic once you get the vibe. π
β¨ SYNOPSIS β¨
bool
mongoc_database_read_write_command_with_opts (
mongoc_database_t *database,
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 this function 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 want to send a raw command to the server without any of this logic, use mongoc_database_command_simple() instead. No cap.
Use this function for commands that both read and write, such as "mapReduce" with an output collection. Thatβs the whole lane.
Read and write concern and collation can be overridden by various sources. In a transaction, read concern and write concern are prohibited in opts.
π¨ Bestie, read this twice: in a transaction, read concern and write concern are prohibited in opts. The function is not gonna let that slide.
The highest-priority sources for these options are listed first. Hereβs the priority table energy, translated into list form:
- Read concern β highest priority first:
opts, thenTransaction, thendatabase. - Write concern β highest priority first:
opts, thenTransaction, thendatabase. - Collation β highest priority first:
opts.
Read preferences are not applied. The write concern is omitted for MongoDB before 3.4. Periodt.
See the example for transactions and for the "distinct" command with opts.
reply is always initialized, and must be freed with bson_destroy(). Literally always β donβt leave your bson_t hanging.
π«Ά Little lore drop: the mongoc_read_prefs_t parameter was included by mistake when this function was introduced in libmongoc 1.5. A command that writes must not obey a read preference. So yeah, that parameter is lowkey just sitting there.
π«Ά PARAMETERS π«Ά
databaseβ Amongoc_database_t.commandβ Abson_tcontaining the command specification.read_prefsβ Ignored. Not used. Itβs giving decorative.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. See the example code formongoc_client_read_command_with_opts(). Read concern requires MongoDB 3.2 or later, otherwise an error is returned.writeConcernβ Construct amongoc_write_concern_tand usemongoc_write_concern_append()to add the write concern toopts. See 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 fromdatabase, and usemongoc_client_session_append()to add the session toopts. See the example code formongoc_client_session_t.collationβ Configure textual comparisons. See Setting Collation Order, and the MongoDB Manual entry on Collation. Collation requires MongoDB 3.2 or later, otherwise an error is returned.serverIdβ To target a specific server, include an int32"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. Thatβs where the per-command deets live.
π ERRORS π
Errors are propagated via the error parameter. Thatβs the whole mood.
π₯ 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. So donβt think you can sneak past that one, bestie.
π EXAMPLE π
See the example code for mongoc_client_read_command_with_opts().
π AUTHOR π
MongoDB, Inc
π COPYRIGHT π
2009-present, MongoDB, Inc.
π Thatβs the page! Source/version 2.5.6, dated Oct 09, 202 (the footer is literally like that), from libmongoc. Stay hydrated, free your bson_t with bson_destroy(), and slay 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