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

ERRORS

41       Errors are propagated via the error parameter.
42

RETURNS

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

EXAMPLE

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

AUTHOR

82       MongoDB, Inc
83
85       2017-present, MongoDB, Inc
86
87
88
89
901.14.0                           Feb 22, 201M9ONGOC_COLLECTION_COMMAND_SIMPLE(3)
Impressum