---
name: "mongoc_collection_find_and_modify_with_opts"
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_collection_find_and_modify_with_opts"
---

# mongoc\_collection\_find\_and\_modify\_with\_opts(3)

## SYNOPSIS

```
bool
mongoc_collection_find_and_modify_with_opts (
   mongoc_collection_t *collection,
   const bson_t *query,
   const mongoc_find_and_modify_opts_t *opts,
   bson_t *reply,
   bson_error_t *error);
```

## PARAMETERS

- •

  **collection**: A *mongoc\_collection\_t*.

- •

  **query**: A *bson\_t* containing the query to locate target document(s).

- •

  **opts**: A *find and modify options*. Must not be NULL.

- •

  **reply**: A maybe-**NULL** pointer to *overwritable storage* for a *bson\_t* to contain the results.

- •

  **error**: An optional location for a *bson\_error\_t* or **NULL**.

## DESCRIPTION

Update and return an object.

**reply** is always initialized, and must be freed with *bson\_destroy()*.

If an unacknowledged write concern is set (through *mongoc\_find\_and\_modify\_opts\_append()*), the output **reply** is always an empty document.

On success, the output **reply** contains the full server reply to the **findAndModify** command. See the *MongoDB Manual page for findAndModify* for the expected server reply.

## ERRORS

Errors are propagated via the **error** parameter.

## RETURNS

Returns **true** if successful. Returns **false** and sets **error** if there are invalid arguments or a server or network error.

A write concern timeout or write concern error is considered a failure.

## EXAMPLE

See the example code for *mongoc\_find\_and\_modify\_opts\_t*.

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
