1MONGOC_FIND_AND_MODIFY_OPTS_APPEMNoDn(g3o)DB C DMrOiNvGeOrC_FIND_AND_MODIFY_OPTS_APPEND(3)
2
3
4

NAME

6       mongoc_find_and_modify_opts_append        -        mongoc_find_and_mod‐
7       ify_opts_append()
8

SYNOPSIS

10          bool
11          mongoc_find_and_modify_opts_append (mongoc_find_and_modify_opts_t *opts,
12                                              const bson_t *extra);
13

PARAMETERS

15       · opts: A mongoc_find_and_modify_opts_t.
16
17       · extra: A bson_t with fields and values to append directly to the fin‐
18         dAndModify command sent to the server.
19

DESCRIPTION

21       Adds arbitrary options to a findAndModify command.
22
23       extra does not have to remain valid after calling this function.
24

RETURNS

26       Returns  true  on  success. If any arguments are invalid, returns false
27       and logs an error.
28

APPENDING OPTIONS TO FINDANDMODIFY

30       opts.c.INDENT 0.0
31
32          void
33          fam_opts (mongoc_collection_t *collection)
34          {
35             mongoc_find_and_modify_opts_t *opts;
36             bson_t reply;
37             bson_t *update;
38             bson_error_t error;
39             bson_t query = BSON_INITIALIZER;
40             mongoc_write_concern_t *wc;
41             bson_t extra = BSON_INITIALIZER;
42             bool success;
43
44
45             /* Find Zlatan Ibrahimovic, the striker */
46             BSON_APPEND_UTF8 (&query, "firstname", "Zlatan");
47             BSON_APPEND_UTF8 (&query, "lastname", "Ibrahimovic");
48             BSON_APPEND_UTF8 (&query, "profession", "Football player");
49
50             /* Bump his age */
51             update = BCON_NEW ("$inc", "{", "age", BCON_INT32 (1), "}");
52
53             opts = mongoc_find_and_modify_opts_new ();
54             mongoc_find_and_modify_opts_set_update (opts, update);
55
56             /* Abort if the operation takes too long. */
57             mongoc_find_and_modify_opts_set_max_time_ms (opts, 100);
58
59             /* Set write concern w: 2 */
60             wc = mongoc_write_concern_new ();
61             mongoc_write_concern_set_w (wc, 2);
62             mongoc_write_concern_append (wc, &extra);
63
64             /* Some future findAndModify option the driver doesn't support conveniently
65              */
66             BSON_APPEND_INT32 (&extra, "futureOption", 42);
67             mongoc_find_and_modify_opts_append (opts, &extra);
68
69             success = mongoc_collection_find_and_modify_with_opts (
70                collection, &query, opts, &reply, &error);
71
72             if (success) {
73                char *str;
74
75                str = bson_as_canonical_extended_json (&reply, NULL);
76                printf ("%s\n", str);
77                bson_free (str);
78             } else {
79                fprintf (
80                   stderr, "Got error: \"%s\" on line %d\n", error.message, __LINE__);
81             }
82
83             bson_destroy (&reply);
84             bson_destroy (&extra);
85             bson_destroy (update);
86             bson_destroy (&query);
87             mongoc_write_concern_destroy (wc);
88             mongoc_find_and_modify_opts_destroy (opts);
89          }
90
91

AUTHOR

93       MongoDB, Inc
94
96       2017-present, MongoDB, Inc
97
98
99
100
1011.14.0                           Feb 22, 2M0O1N9GOC_FIND_AND_MODIFY_OPTS_APPEND(3)
Impressum