[CDRIVER-1164] mongoc_cursor_clone() doesn't work for aggregate Created: 18/Mar/16  Updated: 18/Apr/16  Resolved: 18/Apr/16

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.4.0

Type: Bug Priority: Major - P3
Reporter: Andrea Fontana Assignee: A. Jesse Jiryu Davis
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Calling mongoc_cursor_clone() over a cursor returned by an aggregate, it returns an empty cursor.



 Comments   
Comment by A. Jesse Jiryu Davis [ 18/Apr/16 ]

Andrea, I can't reproduce this issue. Below is the code I used to test. I'm closing this for now, but if you can reproduce this issue please reopen the ticket and provide me some code that demonstrates the bug.

 
static void
test_aggregate_clone (void)
{
   mongoc_collection_t *collection;
   mongoc_database_t *database;
   mongoc_client_t *client;
   mongoc_cursor_t *cursor, *cursor_before, *cursor_after;
   const bson_t *doc;
   bson_error_t error;
   bool r;
   int i;
 
   client = test_framework_client_new ();
   database = get_test_database (client);
   collection = get_test_collection (client, "test_aggregate");
 
   r = mongoc_collection_insert(collection, MONGOC_INSERT_NONE, 
                                tmp_bson ("{'_id': 1}"), NULL, &error);
   ASSERT_OR_PRINT (r, error);
   r = mongoc_collection_insert(collection, MONGOC_INSERT_NONE, 
                                tmp_bson ("{'_id': 2}"), NULL, &error);
   ASSERT_OR_PRINT (r, error);
 
   cursor = mongoc_collection_aggregate(collection, MONGOC_QUERY_NONE, 
                                        tmp_bson ("{}"), NULL, NULL);
   cursor_before = mongoc_cursor_clone (cursor);
   
   i = 0;
   while (mongoc_cursor_next (cursor, &doc)) {
      i++;
   }
   
   ASSERT_OR_PRINT (!mongoc_cursor_error (cursor, &error), error);
   ASSERT_CMPINT (i, ==, 2);
   
   i = 0;
   while (mongoc_cursor_next (cursor_before, &doc)) {
      i++;
   }
   
   ASSERT_OR_PRINT (!mongoc_cursor_error (cursor_before, &error), error);
   ASSERT_CMPINT (i, ==, 2);
 
   cursor_after = mongoc_cursor_clone (cursor);
   i = 0;
   while (mongoc_cursor_next (cursor_after, &doc)) {
      i++;
   }
 
   ASSERT_OR_PRINT (!mongoc_cursor_error (cursor_after, &error), error);
   ASSERT_CMPINT (i, ==, 2);
 
   mongoc_cursor_destroy (cursor);
   mongoc_cursor_destroy (cursor_before);
   mongoc_cursor_destroy (cursor_after);
   mongoc_collection_destroy(collection);
   mongoc_database_destroy(database);
   mongoc_client_destroy(client);
}

Comment by A. Jesse Jiryu Davis [ 22/Mar/16 ]

Thanks for the report!

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