1MONGOC_DATABASE_READ_COMMAND_WITH_OPlTiSbM(mO3oN)nGgOoCc_DATABASE_READ_COMMAND_WITH_OPTS(3)
2
3
4
6 bool
7 mongoc_database_read_command_with_opts (mongoc_database_t *database,
8 const bson_t *command,
9 const mongoc_read_prefs_t *read_prefs,
10 const bson_t *opts,
11 bson_t *reply,
12 bson_error_t *error);
13
14 Execute a command on the server, applying logic that is specific to
15 commands that read, and taking the MongoDB server version into account.
16 To send a raw command to the server without any of this logic, use
17 mongoc_database_command_simple().
18
19 Use this function for commands that read such as "count" or "distinct".
20
21 Read preferences, read concern, and collation can be overridden by var‐
22 ious sources. In a transaction, read concern and write concern are pro‐
23 hibited in opts and the read preference must be primary or NULL. The
24 highest-priority sources for these options are listed first in the fol‐
25 lowing table. No write concern is applied.
26
27 ┌─────────────────┬──────────────┬───────────┐
28 │Read Preferences │ Read Concern │ Collation │
29 ├─────────────────┼──────────────┼───────────┤
30 │read_prefs │ opts │ opts │
31 ├─────────────────┼──────────────┼───────────┤
32 │Transaction │ Transaction │ │
33 ├─────────────────┼──────────────┼───────────┤
34 │database │ │ │
35 └─────────────────┴──────────────┴───────────┘
36
37 See the example for transactions and for the "distinct" command with
38 opts.
39
40 reply is always initialized, and must be freed with bson_destroy().
41
42 This function is considered a retryable read operation. Upon a tran‐
43 sient error (a network error, errors due to replica set failover, etc.)
44 the operation is safely retried once. If retryreads is false in the
45 URI (see mongoc_uri_t) the retry behavior does not apply.
46
47 Retry logic occurs regardless of the underlying command. Retrying
48 mapReduce has the potential for degraded performance. Retrying a get‐
49 More command has the potential to miss results. For those commands, use
50 generic command helpers (like mongoc_database_command_with_opts()) in‐
51 stead.
52
54 • database: A mongoc_database_t.
55
56 • command: A bson_t containing the command specification.
57
58 • read_prefs: An optional mongoc_read_prefs_t.
59
60 • opts: A bson_t containing additional options.
61
62 • reply: A location for the resulting document.
63
64 • error: An optional location for a bson_error_t or NULL.
65
66 opts may be NULL or a BSON document with additional command options:
67
68 • readConcern: Construct a mongoc_read_concern_t and use
69 mongoc_read_concern_append() to add the read concern to opts. See the
70 example code for mongoc_client_read_command_with_opts(). Read concern
71 requires MongoDB 3.2 or later, otherwise an error is returned.
72
73 • sessionId: First, construct a mongoc_client_session_t with
74 mongoc_client_start_session(). You can begin a transaction with
75 mongoc_client_session_start_transaction(), optionally with a
76 mongoc_transaction_opt_t that overrides the options inherited from
77 database, and use mongoc_client_session_append() to add the session
78 to opts. See the example code for mongoc_client_session_t.
79
80 • collation: Configure textual comparisons. See Setting Collation Or‐
81 der, and the MongoDB Manual entry on Collation. Collation requires
82 MongoDB 3.2 or later, otherwise an error is returned.
83
84 • serverId: To target a specific server, include an int32 "serverId"
85 field. Obtain the id by calling mongoc_client_select_server(), then
86 mongoc_server_description_id() on its return value.
87
88 Consult the MongoDB Manual entry on Database Commands for each com‐
89 mand's arguments.
90
92 Errors are propagated via the error parameter.
93
95 Returns true if successful. Returns false and sets error if there are
96 invalid arguments or a server or network error.
97
99 See the example code for mongoc_client_read_command_with_opts().
100
102 MongoDB, Inc
103
105 2017-present, MongoDB, Inc
106
107
108
109
1101.25.1 Nov 0M8O,NG2O0C2_3DATABASE_READ_COMMAND_WITH_OPTS(3)