'\" t .\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "MONGOC_FIND_AND_MODIFY_OPTS_SET_FLAGS" "3" "May 07, 2024" "1.27.1" "libmongoc" .SH SYNOPSIS .INDENT 0.0 .INDENT 3.5 .sp .EX bool mongoc_find_and_modify_opts_set_flags ( mongoc_find_and_modify_opts_t *opts, const mongoc_find_and_modify_flags_t flags); .EE .UNINDENT .UNINDENT .SH PARAMETERS .INDENT 0.0 .IP \(bu 2 \fBopts\fP: A \fI\%mongoc_find_and_modify_opts_t\fP\&. .IP \(bu 2 \fBflags\fP: . .UNINDENT .SH DESCRIPTION .sp Adds one or more flags to the builder. .TS center; |l|l|. _ T{ MONGOC_FIND_AND_MODIFY_NONE T} T{ Default. Doesn\(aqt add anything to the builder. T} _ T{ MONGOC_FIND_AND_MODIFY_REMOVE T} T{ Will instruct find_and_modify to remove the matching document. T} _ T{ MONGOC_FIND_AND_MODIFY_UPSERT T} T{ Update the matching document or, if no document matches, insert the document. T} _ T{ MONGOC_FIND_AND_MODIFY_RETURN_NEW T} T{ Return the resulting document. T} _ .TE .SH RETURNS .sp Returns Returns \fBtrue\fP if it successfully added the option to the builder, otherwise \fBfalse\fP and logs an error. .SH SETTING FLAGS .sp flags.c .INDENT 0.0 .INDENT 3.5 .sp .EX void fam_flags (mongoc_collection_t *collection) { mongoc_find_and_modify_opts_t *opts; bson_t reply; bson_error_t error; bson_t query = BSON_INITIALIZER; bson_t *update; bool success; /* Find Zlatan Ibrahimovic, the striker */ BSON_APPEND_UTF8 (&query, \(dqfirstname\(dq, \(dqZlatan\(dq); BSON_APPEND_UTF8 (&query, \(dqlastname\(dq, \(dqIbrahimovic\(dq); BSON_APPEND_UTF8 (&query, \(dqprofession\(dq, \(dqFootball player\(dq); BSON_APPEND_INT32 (&query, \(dqage\(dq, 34); BSON_APPEND_INT32 (&query, \(dqgoals\(dq, (16 + 35 + 23 + 57 + 16 + 14 + 28 + 84) + (1 + 6 + 62)); /* Add his football position */ update = BCON_NEW (\(dq$set\(dq, \(dq{\(dq, \(dqposition\(dq, BCON_UTF8 (\(dqstriker\(dq), \(dq}\(dq); opts = mongoc_find_and_modify_opts_new (); mongoc_find_and_modify_opts_set_update (opts, update); /* Create the document if it didn\(aqt exist, and return the updated document */ mongoc_find_and_modify_opts_set_flags (opts, MONGOC_FIND_AND_MODIFY_UPSERT | MONGOC_FIND_AND_MODIFY_RETURN_NEW); success = mongoc_collection_find_and_modify_with_opts (collection, &query, opts, &reply, &error); if (success) { char *str; str = bson_as_canonical_extended_json (&reply, NULL); printf (\(dq%s\en\(dq, str); bson_free (str); } else { fprintf (stderr, \(dqGot error: \e\(dq%s\e\(dq on line %d\en\(dq, error.message, __LINE__); } bson_destroy (&reply); bson_destroy (update); bson_destroy (&query); mongoc_find_and_modify_opts_destroy (opts); } .EE .UNINDENT .UNINDENT .sp Outputs: .INDENT 0.0 .INDENT 3.5 .sp .EX { \(dqlastErrorObject\(dq : { \(dqupdatedExisting\(dq : false, \(dqn\(dq : 1, \(dqupserted\(dq : {\(dq$oid\(dq : \(dq56562a99d13e6d86239c7b00\(dq} }, \(dqvalue\(dq : { \(dq_id\(dq : {\(dq$oid\(dq : \(dq56562a99d13e6d86239c7b00\(dq}, \(dqage\(dq : 34, \(dqfirstname\(dq : \(dqZlatan\(dq, \(dqgoals\(dq : 342, \(dqlastname\(dq : \(dqIbrahimovic\(dq, \(dqprofession\(dq : \(dqFootball player\(dq, \(dqposition\(dq : \(dqstriker\(dq }, \(dqok\(dq : 1 } .EE .UNINDENT .UNINDENT .SH AUTHOR MongoDB, Inc .SH COPYRIGHT 2017-present, MongoDB, Inc .\" Generated by docutils manpage writer. .