1MONGOC_CLIENT_COMMAND_WITH_OPTS(3) libmongocMONGOC_CLIENT_COMMAND_WITH_OPTS(3)
2
3
4
6 mongoc_client_command_with_opts - mongoc_client_command_with_opts()
7
9 bool
10 mongoc_client_command_with_opts (
11 mongoc_client_t *client,
12 const char *db_name,
13 const bson_t *command,
14 const mongoc_read_prefs_t *read_prefs,
15 const bson_t *opts,
16 bson_t *reply,
17 bson_error_t *error);
18
19 Execute a command on the server, interpreting opts according to the
20 MongoDB server version. To send a raw command to the server without any
21 of this logic, use mongoc_client_command_simple().
22
23 Read preferences, read and write concern, and collation can be overrid‐
24 den by various sources. The highest-priority sources for these options
25 are listed first:
26
27 ┌─────────────────┬──────────────┬───────────────┬───────────┐
28 │Read Preferences │ Read Concern │ Write Concern │ Collation │
29 ├─────────────────┼──────────────┼───────────────┼───────────┤
30 │read_prefs │ opts │ opts │ opts │
31 ├─────────────────┼──────────────┼───────────────┼───────────┤
32 │Transaction │ Transaction │ Transaction │ │
33 └─────────────────┴──────────────┴───────────────┴───────────┘
34
35 In a transaction, read concern and write concern are prohibited in opts
36 and the read preference must be primary or NULL. See the example for
37 transactions and for the "distinct" command with opts.
38
39 reply is always initialized, and must be freed with bson_destroy().
40
41 This function is not considered a retryable read operation.
42
44 • client: A mongoc_client_t.
45
46 • db_name: The name of the database to run the command on.
47
48 • command: A bson_t containing the command specification.
49
50 • read_prefs: An optional mongoc_read_prefs_t.
51
52 • opts: A bson_t containing additional options.
53
54 • reply: A location for the resulting document.
55
56 • error: An optional location for a bson_error_t or NULL.
57
58 opts may be NULL or a BSON document with additional command options:
59
60 • readConcern: Construct a mongoc_read_concern_t and use
61 mongoc_read_concern_append() to add the read concern to opts. See the
62 example code for mongoc_client_read_command_with_opts(). Read concern
63 requires MongoDB 3.2 or later, otherwise an error is returned.
64
65 • writeConcern: Construct a mongoc_write_concern_t and use
66 mongoc_write_concern_append() to add the write concern to opts. See
67 the example code for mongoc_client_write_command_with_opts().
68
69 • sessionId: First, construct a mongoc_client_session_t with
70 mongoc_client_start_session(). You can begin a transaction with
71 mongoc_client_session_start_transaction(), optionally with a
72 mongoc_transaction_opt_t that overrides the options inherited from
73 client, and use mongoc_client_session_append() to add the session to
74 opts. See the example code for mongoc_client_session_t.
75
76 • collation: Configure textual comparisons. See Setting Collation Or‐
77 der, and the MongoDB Manual entry on Collation. Collation requires
78 MongoDB 3.2 or later, otherwise an error is returned.
79
80 • serverId: To target a specific server, include an int32 "serverId"
81 field. Obtain the id by calling mongoc_client_select_server(), then
82 mongoc_server_description_id() on its return value.
83
84 Consult the MongoDB Manual entry on Database Commands for each com‐
85 mand's arguments.
86
88 Errors are propagated via the error parameter.
89
91 Returns true if successful. Returns false and sets error if there are
92 invalid arguments or a server or network error.
93
94 The reply is not parsed for a write concern timeout or write concern
95 error.
96
98 See the example code for mongoc_client_read_command_with_opts().
99
101 MongoDB, Inc
102
104 2017-present, MongoDB, Inc
105
106
107
108
1091.24.3 Aug 17, 2023MONGOC_CLIENT_COMMAND_WITH_OPTS(3)