1MONGOC_COLLECTION_COMMAND_SIMPLE(3)libmongocMONGOC_COLLECTION_COMMAND_SIMPLE(3)
2
3
4

NAME

6       mongoc_collection_command_simple - mongoc_collection_command_simple()
7

SYNOPSIS

9          bool
10          mongoc_collection_command_simple (mongoc_collection_t *collection,
11                                            const bson_t *command,
12                                            const mongoc_read_prefs_t *read_prefs,
13                                            bson_t *reply,
14                                            bson_error_t *error);
15

PARAMETERS

17collection: A mongoc_collection_t.
18
19command: A bson_t containing the command to execute.
20
21read_prefs:  An  optional mongoc_read_prefs_t. Otherwise, the command
22         uses mode MONGOC_READ_PRIMARY.
23
24reply: A location to initialize a  bson_t.  This  should  be  on  the
25         stack.
26
27error: An optional location for a bson_error_t or NULL.
28

DESCRIPTION

30       This  is  a  simplified version of mongoc_collection_command() that re‐
31       turns the first result document in reply. The collection's read prefer‐
32       ence,  read  concern, and write concern are not applied to the command.
33       The parameter reply is initialized even upon failure to simplify memory
34       management.
35
36       This  function  tries  to  unwrap an embedded error in the command when
37       possible. The unwrapped error will be propagated via the error  parame‐
38       ter. Additionally, the result document is set in reply.
39
40       This function is not considered a retryable read operation.
41

ERRORS

43       Errors are propagated via the error parameter.
44

RETURNS

46       Returns  true  if successful. Returns false and sets error if there are
47       invalid arguments or a server or network error.
48
49       This function does not check the server response for  a  write  concern
50       error or write concern timeout.
51

EXAMPLE

53       The following is an example of executing the ping command.
54
55          #include <bson/bson.h>
56          #include <mongoc/mongoc.h>
57          #include <stdio.h>
58
59          static void
60          do_ping (mongoc_collection_t *collection)
61          {
62             bson_error_t error;
63             bson_t *cmd;
64             bson_t reply;
65             char *str;
66
67             cmd = BCON_NEW ("ping", BCON_INT32 (1));
68
69             if (mongoc_collection_command_simple (
70                    collection, cmd, NULL, &reply, &error)) {
71                str = bson_as_canonical_extended_json (&reply, NULL);
72                printf ("Got reply: %s\n", str);
73                bson_free (str);
74             } else {
75                fprintf (stderr, "Got error: %s\n", error.message);
76             }
77
78             bson_destroy (&reply);
79             bson_destroy (cmd);
80          }
81
82

AUTHOR

84       MongoDB, Inc
85
87       2017-present, MongoDB, Inc
88
89
90
91
921.24.3                           Aug 17, 202M3ONGOC_COLLECTION_COMMAND_SIMPLE(3)
Impressum