1MONGOC_FIND_AND_MODIFY_OPTS_SET_FLAGlSi(b3mM)oOnNgGoOcC_FIND_AND_MODIFY_OPTS_SET_FLAGS(3)
2
3
4

NAME

6       mongoc_find_and_modify_opts_set_flags       -      mongoc_find_and_mod‐
7       ify_opts_set_flags()
8

SYNOPSIS

10          bool
11          mongoc_find_and_modify_opts_set_flags (
12             mongoc_find_and_modify_opts_t *opts,
13             const mongoc_find_and_modify_flags_t flags);
14

PARAMETERS

16opts: A mongoc_find_and_modify_opts_t.
17
18flags: .
19

DESCRIPTION

21       Adds one or more flags to the builder.
22
23              ┌───────────────────────────┬────────────────────────────┐
24              │MONGOC_FIND_AND_MOD‐       │ Default.  Doesn't add any‐ │
25              │IFY_NONE                   │ thing to the builder.      │
26              ├───────────────────────────┼────────────────────────────┤
27              │MONGOC_FIND_AND_MODIFY_RE‐ │ Will              instruct │
28              │MOVE                       │ find_and_modify to  remove │
29              │                           │ the matching document.     │
30              ├───────────────────────────┼────────────────────────────┤
31              │MONGOC_FIND_AND_MODIFY_UP‐ │ Update the matching  docu‐ │
32              │SERT                       │ ment  or,  if  no document │
33              │                           │ matches, insert the  docu‐ │
34              │                           │ ment.                      │
35              ├───────────────────────────┼────────────────────────────┤
36              │MONGOC_FIND_AND_MODIFY_RE‐ │ Return the resulting docu‐ │
37              │TURN_NEW                   │ ment.                      │
38              └───────────────────────────┴────────────────────────────┘
39

RETURNS

41       Returns  Returns  true  if  it  successfully  added  the  option to the
42       builder, otherwise false and logs an error.
43

SETTING FLAGS

45       flags.c
46
47          void
48          fam_flags (mongoc_collection_t *collection)
49          {
50             mongoc_find_and_modify_opts_t *opts;
51             bson_t reply;
52             bson_error_t error;
53             bson_t query = BSON_INITIALIZER;
54             bson_t *update;
55             bool success;
56
57
58             /* Find Zlatan Ibrahimovic, the striker */
59             BSON_APPEND_UTF8 (&query, "firstname", "Zlatan");
60             BSON_APPEND_UTF8 (&query, "lastname", "Ibrahimovic");
61             BSON_APPEND_UTF8 (&query, "profession", "Football player");
62             BSON_APPEND_INT32 (&query, "age", 34);
63             BSON_APPEND_INT32 (
64                &query, "goals", (16 + 35 + 23 + 57 + 16 + 14 + 28 + 84) + (1 + 6 + 62));
65
66             /* Add his football position */
67             update = BCON_NEW ("$set", "{", "position", BCON_UTF8 ("striker"), "}");
68
69             opts = mongoc_find_and_modify_opts_new ();
70
71             mongoc_find_and_modify_opts_set_update (opts, update);
72
73             /* Create the document if it didn't exist, and return the updated document */
74             mongoc_find_and_modify_opts_set_flags (
75                opts, MONGOC_FIND_AND_MODIFY_UPSERT | MONGOC_FIND_AND_MODIFY_RETURN_NEW);
76
77             success = mongoc_collection_find_and_modify_with_opts (
78                collection, &query, opts, &reply, &error);
79
80             if (success) {
81                char *str;
82
83                str = bson_as_canonical_extended_json (&reply, NULL);
84                printf ("%s\n", str);
85                bson_free (str);
86             } else {
87                fprintf (
88                   stderr, "Got error: \"%s\" on line %d\n", error.message, __LINE__);
89             }
90
91             bson_destroy (&reply);
92             bson_destroy (update);
93             bson_destroy (&query);
94             mongoc_find_and_modify_opts_destroy (opts);
95          }
96
97
98       Outputs:
99
100          {
101             "lastErrorObject" : {
102                "updatedExisting" : false,
103                "n" : 1,
104                "upserted" : {"$oid" : "56562a99d13e6d86239c7b00"}
105             },
106                                 "value" : {
107                                    "_id" : {"$oid" : "56562a99d13e6d86239c7b00"},
108                                    "age" : 34,
109                                    "firstname" : "Zlatan",
110                                    "goals" : 342,
111                                    "lastname" : "Ibrahimovic",
112                                    "profession" : "Football player",
113                                    "position" : "striker"
114                                 },
115                                           "ok" : 1
116          }
117

AUTHOR

119       MongoDB, Inc
120
122       2017-present, MongoDB, Inc
123
124
125
126
1271.23.1                           Oct 20M,ON2G0O2C2_FIND_AND_MODIFY_OPTS_SET_FLAGS(3)
Impressum