---
name: "mongoc_find_and_modify_opts_append"
section: "3"
platform: "linux"
package: "libmongoc-doc"
version: "1.30.4-1+deb13u3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mongoc_find_and_modify_opts_append"
---

# mongoc\_find\_and\_modify\_opts\_append(3)

## SYNOPSIS

```
bool
mongoc_find_and_modify_opts_append (mongoc_find_and_modify_opts_t *opts,
                                    const bson_t *extra);
```

## PARAMETERS

- •

  **opts**: A *mongoc\_find\_and\_modify\_opts\_t*.

- •

  **extra**: A *bson\_t* with fields and values to append directly to *the findAndModify command* sent to the server.

## DESCRIPTION

Adds arbitrary options to *the findAndModify command*.

**extra** does not have to remain valid after calling this function.

**extra** may be NULL or a BSON document with additional command options:

- •

  **writeConcern**: Construct a *mongoc\_write\_concern\_t* and use *mongoc\_write\_concern\_append()* to add the write concern to **opts**. See the example code for *mongoc\_client\_write\_command\_with\_opts()*.

- •

  **sessionId**: First, construct a *mongoc\_client\_session\_t* with *mongoc\_client\_start\_session()*. You can begin a transaction with *mongoc\_client\_session\_start\_transaction()*, optionally with a *mongoc\_transaction\_opt\_t* that overrides the options inherited from **collection**, and use *mongoc\_client\_session\_append()* to add the session to **opts**. See the example code for *mongoc\_client\_session\_t*.

- •

  **hint**: A document or string that specifies the index to use to support the query predicate.

- •

  **let**: A BSON document consisting of any number of parameter names, each followed by definitions of constants in the MQL Aggregate Expression language.

- •

  **comment**: A *bson\_value\_t* specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Requires MongoDB 4.4 or later.

## RETURNS

Returns true on success. If any arguments are invalid, returns false and logs an error.

## APPENDING OPTIONS TO FINDANDMODIFY

opts.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't 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\n", str);
      bson_free (str);
   } else {
      fprintf (stderr, "Got error: \"%s\" on line %d\n", error.message, (int) (__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);
}
```

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
