1MONGOC_COLLECTION_COMMAND_SIMPLEM(o3n)goDB C DriMvOeNrGOC_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

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

DESCRIPTION

30       This  is  a  simplified  version  of  mongoc_collection_command()  that
31       returns the first result document in reply. The collection's read pref‐
32       erence, 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 collection stats command.
54
55          #include <bson/bson.h>
56          #include <mongoc/mongoc.h>
57          #include <stdio.h>
58
59          static void
60          print_collection_stats (mongoc_collection_t *collection)
61          {
62             bson_error_t error;
63             const char *name;
64             bson_t *cmd;
65             bson_t reply;
66
67             name = mongoc_collection_get_name (collection);
68             cmd = BCON_NEW ("collStats", BCON_UTF8 (name));
69
70             if (mongoc_collection_command_simple (
71                    collection, cmd, NULL, &reply, &error)) {
72                str = bson_as_canonical_extended_json (&reply, NULL);
73                printf ("%s\n", str);
74                bson_free (str);
75             } else {
76                fprintf (stderr, "%s\n", error.message);
77             }
78
79             bson_destroy (&reply);
80             bson_destroy (cmd);
81          }
82

AUTHOR

84       MongoDB, Inc
85
87       2017-present, MongoDB, Inc
88
89
90
91
921.15.2                           Nov 06, 201M9ONGOC_COLLECTION_COMMAND_SIMPLE(3)
Impressum