- MongoDB C Driver 1.13.1 »
- API Reference »
- mongoc_cursor_t

# mongoc_cursor_new_from_command_reply()

## Synopsis

    mongoc_cursor_t *
    mongoc_cursor_new_from_command_reply (mongoc_client_t *client,
                                          bson_t *reply,
                                          uint32_t server_id);
       BSON_GNUC_DEPRECATED_FOR (mongoc_cursor_new_from_command_reply_with_opts);

## Deprecated

This function is deprecated and should not be used in new code.

Please use mongoc_cursor_new_from_command_reply_with_opts() instead.

When migrating from the deprecated mongoc_cursor_new_from_command_reply() to mongoc_cursor_new_from_command_reply_with_opts(), note that options previously passed to the `reply` argument (e.g. “batchSize”) must instead be provided in the `opts` argument.

## 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` and must not be accessed afterward.
- `server_id`: The opaque id of the server used to execute the command.

## 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` is a low-level function that initializes a mongoc_cursor_t from such a reply. Additional options such as “tailable” or “awaitData” can be included in the reply.

When synthesizing a completed cursor response that has no more batches (i.e. with cursor id 0), set `server_id` to 0 as well.

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().

Created using Sphinx 1.8.3, based on Sphinx Readable Theme.