.\" Man page generated from reStructuredText. . .TH "MONGOC_FIND_AND_MODIFY_OPTS_APPEND" "3" "Jun 04, 2021" "1.17.6" "libmongoc" .SH NAME mongoc_find_and_modify_opts_append \- mongoc_find_and_modify_opts_append() . .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_append (mongoc_find_and_modify_opts_t *opts, const bson_t *extra); .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 \fBextra\fP: A \fI\%bson_t\fP with fields and values to append directly to the findAndModify command sent to the server. .UNINDENT .SH DESCRIPTION .sp Adds arbitrary options to a \fI\%findAndModify\fP command. .sp \fBextra\fP does not have to remain valid after calling this function. .sp \fBextra\fP may be NULL or a BSON document with additional command options: .INDENT 0.0 .IP \(bu 2 \fBwriteConcern\fP: Construct a \fBmongoc_write_concern_t\fP and use \fBmongoc_write_concern_append\fP to add the write concern to \fBopts\fP\&. See the example code for \fBmongoc_client_write_command_with_opts\fP\&. .IP \(bu 2 \fBsessionId\fP: First, construct a \fBmongoc_client_session_t\fP with \fBmongoc_client_start_session\fP\&. You can begin a transaction with \fBmongoc_client_session_start_transaction\fP, optionally with a \fBmongoc_transaction_opt_t\fP that overrides the options inherited from \fBcollection\fP, and use \fBmongoc_client_session_append\fP to add the session to \fBopts\fP\&. See the example code for \fBmongoc_client_session_t\fP\&. .IP \(bu 2 \fBhint\fP: A document or string that specifies the index to use to support the query predicate. .UNINDENT .SH RETURNS .sp Returns true on success. If any arguments are invalid, returns false and logs an error. .SH APPENDING OPTIONS TO FINDANDMODIFY .sp opts.c .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C void fam_opts (mongoc_collection_t *collection) { mongoc_find_and_modify_opts_t *opts; bson_t reply; bson_t *update; bson_error_t error; bson_t query = BSON_INITIALIZER; mongoc_write_concern_t *wc; bson_t extra = BSON_INITIALIZER; bool success; /* Find Zlatan Ibrahimovic, the striker */ BSON_APPEND_UTF8 (&query, "firstname", "Zlatan"); BSON_APPEND_UTF8 (&query, "lastname", "Ibrahimovic"); BSON_APPEND_UTF8 (&query, "profession", "Football player"); /* Bump his age */ update = BCON_NEW ("$inc", "{", "age", BCON_INT32 (1), "}"); opts = mongoc_find_and_modify_opts_new (); mongoc_find_and_modify_opts_set_update (opts, update); /* Abort if the operation takes too long. */ mongoc_find_and_modify_opts_set_max_time_ms (opts, 100); /* Set write concern w: 2 */ wc = mongoc_write_concern_new (); mongoc_write_concern_set_w (wc, 2); mongoc_write_concern_append (wc, &extra); /* Some future findAndModify option the driver doesn\(aqt support conveniently */ BSON_APPEND_INT32 (&extra, "futureOption", 42); mongoc_find_and_modify_opts_append (opts, &extra); 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 (&extra); bson_destroy (update); bson_destroy (&query); mongoc_write_concern_destroy (wc); mongoc_find_and_modify_opts_destroy (opts); } .ft P .fi .UNINDENT .UNINDENT .SH AUTHOR MongoDB, Inc .SH COPYRIGHT 2017-present, MongoDB, Inc .\" Generated by docutils manpage writer. .