[CDRIVER-1842] Example using mongoc_cursor_new_from_command_reply with mongoc_client_command_with_opts Created: 18/Oct/16  Updated: 20/Oct/16  Resolved: 20/Oct/16

Status: Closed
Project: C Driver
Component/s: docs
Affects Version/s: 1.5.0
Fix Version/s: 1.5.0

Type: New Feature Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on CDRIVER-1844 Add "serverId" option for mongoc_clie... Closed
Epic Link: Flexible opts
Backwards Compatibility: Fully Compatible

 Comments   
Comment by A. Jesse Jiryu Davis [ 20/Oct/16 ]

driver-php here's an example which will work once CDRIVER-1844 is done:

   mongoc_server_description_t *sd;
   uint32_t server_id;
   bson_t *cmd;
   bson_t *opts;
   bson_t reply;
   bool r;
   mongoc_cursor_t *cmd_cursor;
 
   sd = mongoc_topology_select (client->topology, MONGOC_SS_READ,
                                NULL, &error);
 
   server_id = mongoc_server_description_id (sd);
   cmd = BCON_NEW ("aggregate", BCON_UTF8 ("my_collection"),
                   "pipeline", "[", "]");
   opts = BCON_NEW ("serverId", BCON_INT64 (server_id),
                    "cursor", "{", "}");
   r = mongoc_client_read_command_with_opts (client, "test", cmd,
                                             NULL /* prefs */, opts, &reply,
                                             &error);
 
   if (!r) {
      printf ("error: %s\n", error.message);
      return;
   }
 
   cmd_cursor = mongoc_cursor_new_from_command_reply (client, &reply, server_id);

Generated at Wed Feb 07 21:13:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.