.\" Man page generated from reStructuredText. . .TH "MONGOC_FIND_AND_MODIFY_OPTS_SET_UPDATE" "3" "Jun 04, 2021" "1.17.6" "libmongoc" .SH NAME mongoc_find_and_modify_opts_set_update \- mongoc_find_and_modify_opts_set_update() . .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 .. .SH SYNOPSIS .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C bool mongoc_find_and_modify_opts_set_update (mongoc_find_and_modify_opts_t *opts, const bson_t *update); .ft P .fi .UNINDENT .UNINDENT .SH PARAMETERS .INDENT 0.0 .IP \(bu 2 \fBopts\fP: A \fBmongoc_find_and_modify_opts_t\fP\&. .IP \(bu 2 \fBupdate\fP: The \fBupdate\fP document is the same format as the \fBupdate\fP document passed to \fBmongoc_collection_update\fP\&. .UNINDENT .SH DESCRIPTION .sp Adds update argument to the builder. .sp \fBupdate\fP does not have to remain valid after calling this function. .SH RETURNS .sp Returns \fBtrue\fP if it successfully added the option to the builder, otherwise \fBfalse\fP\&. .SH SETTING UPDATE .sp update.c .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C void fam_update (mongoc_collection_t *collection) { mongoc_find_and_modify_opts_t *opts; bson_t *update; bson_t reply; bson_error_t error; bson_t query = BSON_INITIALIZER; bool success; /* Find Zlatan Ibrahimovic */ BSON_APPEND_UTF8 (&query, "firstname", "Zlatan"); BSON_APPEND_UTF8 (&query, "lastname", "Ibrahimovic"); /* Make him a book author */ update = BCON_NEW ("$set", "{", "author", BCON_BOOL (true), "}"); opts = mongoc_find_and_modify_opts_new (); /* Note that the document returned is the _previous_ version of the document * To fetch the modified new version, use * mongoc_find_and_modify_opts_set_flags (opts, * MONGOC_FIND_AND_MODIFY_RETURN_NEW); */ mongoc_find_and_modify_opts_set_update (opts, update); 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 ("%s\en", str); bson_free (str); } else { fprintf ( stderr, "Got error: \e"%s\e" on line %d\en", error.message, __LINE__); } bson_destroy (&reply); bson_destroy (update); bson_destroy (&query); mongoc_find_and_modify_opts_destroy (opts); } .ft P .fi .UNINDENT .UNINDENT .sp Outputs: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C { "lastErrorObject" : {"updatedExisting" : true, "n" : 1}, "value" : { "_id" : {"$oid" : "56562a99d13e6d86239c7b00"}, "age" : 35, "firstname" : "Zlatan", "goals" : 342, "lastname" : "Ibrahimovic", "profession" : "Football player", "position" : "striker" }, "ok" : 1 } .ft P .fi .UNINDENT .UNINDENT .SH AUTHOR MongoDB, Inc .SH COPYRIGHT 2017-present, MongoDB, Inc .\" Generated by docutils manpage writer. .