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

SYNOPSIS

6          bool
7          mongoc_find_and_modify_opts_set_flags (
8             mongoc_find_and_modify_opts_t *opts,
9             const mongoc_find_and_modify_flags_t flags);
10

PARAMETERS

12opts: A mongoc_find_and_modify_opts_t.
13
14flags: .
15

DESCRIPTION

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

RETURNS

37       Returns Returns true  if  it  successfully  added  the  option  to  the
38       builder, otherwise false and logs an error.
39

SETTING FLAGS

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

AUTHOR

115       MongoDB, Inc
116
118       2017-present, MongoDB, Inc
119
120
121
122
1231.25.1                           Nov 08M,ON2G0O2C3_FIND_AND_MODIFY_OPTS_SET_FLAGS(3)
Impressum