[CXX-1337] Tailable cursor don't resume Created: 10/May/17  Updated: 10/May/17  Resolved: 10/May/17

Status: Closed
Project: C++ Driver
Component/s: API
Affects Version/s: 3.1.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Yoann Couillec Assignee: David Golden
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CXX-1001 mongocxx::cursor.begin() increments t... Closed

 Description   

I try to use tailable cursor by inserting a document in a capped collection after iterating over the collection. Here is the code I run:

  mongocxx::uri uri("XXX");
  mongocxx::client client(uri);
  bsoncxx::oid id;
  std::string name = id.to_string();
  mongocxx::database db = client[name];
  mongocxx::options::create_collection opt;
  opt.capped(true).size(10000).max(3);
  mongocxx::collection col = db.create_collection(name,opt);
  bsoncxx::builder::stream::document insert { };
  int n = 13;
  for (int i = 0; i < n; i++) {
    insert << "CollectionTest::CreateCappedCollection" << "ok"
        << "capped_id" << id;
    col.insert_one(insert.view());
    insert.clear();
  }
  bsoncxx::builder::stream::document docFind { };
  mongocxx::options::find optFind;
  optFind.cursor_type(mongocxx::cursor::type::k_tailable);
  mongocxx::cursor cursor = col.find(docFind.view(),optFind);
  ASSERT_TRUE(cursor.begin() != cursor.end());
  int m = 0;
  for (auto doc : cursor){
    m++;
  }
  ASSERT_EQ(3,m);
  insert << "CollectionTest::CreateCappedCollection" << "ok"
      << "capped_id" << id;
  col.insert_one(insert.view());
  ASSERT_TRUE(cursor.begin() != cursor.end());
  for (auto doc : cursor){
    m++;
  }
  ASSERT_EQ(4,m);

Since C++ driver calls C driver, the function involved is _mongoc_cursor_next which seems to be ok but it's hard to confirm.

In other hands, in test/collection_mocked.cpp (from C++ driver) we can see that:

	mongocxx::stdx::optional<mongocxx::cursor::type> expected_cursor_type{};
	mongocxx::stdx::optional<bsoncxx::types::value> expected_hint{};
	mongocxx::stdx::optional<bool> expected_no_cursor_timeout;
	mongocxx::stdx::optional<bsoncxx::document::view> expected_sort{};
 
	collection_find_with_opts->interpose([&](mongoc_collection_t*, const bson_t* filter,
                                                 const bson_t* opts,
                                                 const mongoc_read_prefs_t* read_prefs) {
            collection_find_called = true;
 
            bsoncxx::document::view filter_view{bson_get_data(filter), filter->len};
            bsoncxx::document::view opts_view{bson_get_data(opts), opts->len};
 
            REQUIRE(filter_view == doc);
 
            if (expected_allow_partial_results) {
		REQUIRE(opts_view["allowPartialResults"].get_bool().value ==
			*expected_allow_partial_results);
            }
            if (expected_comment) {
		REQUIRE(opts_view["comment"].get_utf8().value == *expected_comment);
            }
            if (expected_cursor_type) {
		bsoncxx::document::element tailable = opts_view["tailable"];
		bsoncxx::document::element awaitData = opts_view["awaitData"];
...

The thing is that the variable expected_cursor_type is declared and tested without assignement !



 Comments   
Comment by David Golden [ 10/May/17 ]

Thank you for the report! I'm sorry you encountered this problem.

This looks like it's probably a duplicate of CXX-1001, which is a bug where the cursor increments when you call begin() (thus discarding a document). We're going to be shipping 3.2.0-rc0 soon. You can wait for that or you can try the master branch of the repository and see if they fix your issue.

Regards,
David

Generated at Wed Feb 07 22:02:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.