1MONGOC_FIND_AND_MODIFY_OPTS_SET_MMAOXN_lGTiOIbCMm_EoF_nIMgNSoD(c_3A)ND_MODIFY_OPTS_SET_MAX_TIME_MS(3)
2
3
4
6 bool
7 mongoc_find_and_modify_opts_set_max_time_ms (
8 mongoc_find_and_modify_opts_t *opts, uint32_t max_time_ms);
9
11 • opts: A mongoc_find_and_modify_opts_t.
12
13 • max_time_ms: The maximum server-side execution time permitted, in
14 milliseconds, or 0 to specify no maximum time (the default setting).
15
17 Adds a maxTimeMS argument to the builder.
18
20 Returns true if it successfully added the option to the builder, other‐
21 wise false and logs an error.
22
23 Note: although max_time_ms is a uint32_t, it is possible to set it as a
24 uint64_t through the options arguments in some cursor returning func‐
25 tions like mongoc_collection_find_with_opts().
26
28 opts.c
29
30 void
31 fam_opts (mongoc_collection_t *collection)
32 {
33 mongoc_find_and_modify_opts_t *opts;
34 bson_t reply;
35 bson_t *update;
36 bson_error_t error;
37 bson_t query = BSON_INITIALIZER;
38 mongoc_write_concern_t *wc;
39 bson_t extra = BSON_INITIALIZER;
40 bool success;
41
42
43 /* Find Zlatan Ibrahimovic, the striker */
44 BSON_APPEND_UTF8 (&query, "firstname", "Zlatan");
45 BSON_APPEND_UTF8 (&query, "lastname", "Ibrahimovic");
46 BSON_APPEND_UTF8 (&query, "profession", "Football player");
47
48 /* Bump his age */
49 update = BCON_NEW ("$inc", "{", "age", BCON_INT32 (1), "}");
50
51 opts = mongoc_find_and_modify_opts_new ();
52 mongoc_find_and_modify_opts_set_update (opts, update);
53
54 /* Abort if the operation takes too long. */
55 mongoc_find_and_modify_opts_set_max_time_ms (opts, 100);
56
57 /* Set write concern w: 2 */
58 wc = mongoc_write_concern_new ();
59 mongoc_write_concern_set_w (wc, 2);
60 mongoc_write_concern_append (wc, &extra);
61
62 /* Some future findAndModify option the driver doesn't support conveniently
63 */
64 BSON_APPEND_INT32 (&extra, "futureOption", 42);
65 mongoc_find_and_modify_opts_append (opts, &extra);
66
67 success = mongoc_collection_find_and_modify_with_opts (
68 collection, &query, opts, &reply, &error);
69
70 if (success) {
71 char *str;
72
73 str = bson_as_canonical_extended_json (&reply, NULL);
74 printf ("%s\n", str);
75 bson_free (str);
76 } else {
77 fprintf (
78 stderr, "Got error: \"%s\" on line %d\n", error.message, __LINE__);
79 }
80
81 bson_destroy (&reply);
82 bson_destroy (&extra);
83 bson_destroy (update);
84 bson_destroy (&query);
85 mongoc_write_concern_destroy (wc);
86 mongoc_find_and_modify_opts_destroy (opts);
87 }
88
89
91 MongoDB, Inc
92
94 2017-present, MongoDB, Inc
95
96
97
98
991.25.1 MNOoNvGO0C8_,FI2N0D2_3AND_MODIFY_OPTS_SET_MAX_TIME_MS(3)