1MONGOC_FIND_AND_MODIFY_OPTS_SET_MMoMAnOXgN_oGTDOIBCM_ECF_IMDNSrD(i_3vA)eNrD_MODIFY_OPTS_SET_MAX_TIME_MS(3)
2
3
4

NAME

6       mongoc_find_and_modify_opts_set_max_time_ms    -   mongoc_find_and_mod‐
7       ify_opts_set_max_time_ms()
8

SYNOPSIS

10          bool
11          mongoc_find_and_modify_opts_set_max_time_ms (
12             mongoc_find_and_modify_opts_t *opts, uint32_t max_time_ms);
13

PARAMETERS

15       · opts: A mongoc_find_and_modify_opts_t.
16
17       · max_time_ms: The maximum server-side  execution  time  permitted,  in
18         milliseconds, or 0 to specify no maximum time (the default setting).
19

DESCRIPTION

21       Adds a maxTimeMS argument to the builder.
22

RETURNS

24       Returns true if it successfully added the option to the builder, other‐
25       wise false and logs an error.
26
27       Note: although max_time_ms is a uint32_t, it is possible to set it as a
28       uint64_t  through  the options arguments in some cursor returning func‐
29       tions like mongoc_collection_find_with_opts().
30

SETTING MAXTIMEMS

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

AUTHOR

95       MongoDB, Inc
96
98       2017-present, MongoDB, Inc
99
100
101
102
1031.15.2                          MNOoNvGO0C6_,FI2N0D1_9AND_MODIFY_OPTS_SET_MAX_TIME_MS(3)
Impressum