---
name: "mongoc_cursor_new_from_command_reply_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_cursor_new_from_command_reply_with_opts"
---

# mongoc\_cursor\_new\_from\_command\_reply\_with\_opts(3)

## SYNOPSIS

```
mongoc_cursor_t *
mongoc_cursor_new_from_command_reply_with_opts (mongoc_client_t *client,
                                                bson_t *reply,
                                                const bson_t *opts);
```

## PARAMETERS

- •

  **client**: A *mongoc\_client\_t*.

- •

  **reply**: The reply to a command, such as "aggregate", "find", or "listCollections", that returns a cursor document. The reply is destroyed by **mongoc\_cursor\_new\_from\_command\_reply\_with\_opts** and must not be accessed afterward.

- •

  **opts**: A *bson\_t*.

**opts** may be NULL or a BSON document with additional options, which have the same meaning for this function as for *mongoc\_collection\_find\_with\_opts()*:

- •

  **awaitData**

- •

  **batchSize**

- •

  **limit**

- •

  **maxAwaitTimeMS**

- •

  **serverId**

- •

  **sessionId**

- •

  **skip**

- •

  **tailable**

## DESCRIPTION

Some MongoDB commands return a "cursor" document. For example, given an "aggregate" command:

```
{ "aggregate" : "collection", "pipeline" : [], "cursor" : {}}
```

The server replies:

```
{
   "cursor" : {
      "id" : 1234,
      "ns" : "db.collection",
      "firstBatch" : [ ]
   },
   "ok" : 1
}
```

**mongoc\_cursor\_new\_from\_command\_reply\_with\_opts** is a low-level function that initializes a *mongoc\_cursor\_t* from such a reply.

When synthesizing a completed cursor response that has no more batches (i.e. with cursor id 0), **serverId** may be 0. If the cursor response is not completed (i.e. with non-zero cursor id), pass the **serverId** of the server used to create the cursor.

Use this function only for building a language driver that wraps the C Driver. When writing applications in C, higher-level functions such as *mongoc\_collection\_aggregate()* are more appropriate, and ensure compatibility with a range of MongoDB versions.

## RETURNS

A *mongoc\_cursor\_t*. On failure, the cursor's error is set. Check for failure with *mongoc\_cursor\_error()*.

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
