1MONGOC_COLLECTION_COMMAND_SIMPLE(3)libmongocMONGOC_COLLECTION_COMMAND_SIMPLE(3)
2
3
4
6 bool
7 mongoc_collection_command_simple (mongoc_collection_t *collection,
8 const bson_t *command,
9 const mongoc_read_prefs_t *read_prefs,
10 bson_t *reply,
11 bson_error_t *error);
12
14 • collection: A mongoc_collection_t.
15
16 • command: A bson_t containing the command to execute.
17
18 • read_prefs: An optional mongoc_read_prefs_t. Otherwise, the command
19 uses mode MONGOC_READ_PRIMARY.
20
21 • reply: A location to initialize a bson_t. This should be on the
22 stack.
23
24 • error: An optional location for a bson_error_t or NULL.
25
27 This is a simplified version of mongoc_collection_command() that re‐
28 turns the first result document in reply. The collection's read prefer‐
29 ence, read concern, and write concern are not applied to the command.
30 The parameter reply is initialized even upon failure to simplify memory
31 management.
32
33 This function tries to unwrap an embedded error in the command when
34 possible. The unwrapped error will be propagated via the error parame‐
35 ter. Additionally, the result document is set in reply.
36
37 This function is not considered a retryable read operation.
38
40 Errors are propagated via the error parameter.
41
43 Returns true if successful. Returns false and sets error if there are
44 invalid arguments or a server or network error.
45
46 This function does not check the server response for a write concern
47 error or write concern timeout.
48
50 The following is an example of executing the ping command.
51
52 #include <bson/bson.h>
53 #include <mongoc/mongoc.h>
54 #include <stdio.h>
55
56 static void
57 do_ping (mongoc_collection_t *collection)
58 {
59 bson_error_t error;
60 bson_t *cmd;
61 bson_t reply;
62 char *str;
63
64 cmd = BCON_NEW ("ping", BCON_INT32 (1));
65
66 if (mongoc_collection_command_simple (
67 collection, cmd, NULL, &reply, &error)) {
68 str = bson_as_canonical_extended_json (&reply, NULL);
69 printf ("Got reply: %s\n", str);
70 bson_free (str);
71 } else {
72 fprintf (stderr, "Got error: %s\n", error.message);
73 }
74
75 bson_destroy (&reply);
76 bson_destroy (cmd);
77 }
78
79
81 MongoDB, Inc
82
84 2017-present, MongoDB, Inc
85
86
87
88
891.25.1 Nov 08, 202M3ONGOC_COLLECTION_COMMAND_SIMPLE(3)