Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-1337

Tailable cursor don't resume

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.1.1
    • Component/s: API
    • Labels:
      None

      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 !

            Assignee:
            david.golden@mongodb.com David Golden
            Reporter:
            yoann.couillec@amadeus.com Yoann Couillec
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: