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

Having more than one iterator per cursor violates mongoc lifecycle constraints

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.1.0
    • Affects Version/s: None
    • Component/s: Implementation
    • None
    • Major Change

      Given a single cursor, iterator construction and iteration result in the construction of bsoncxx::document::view objects wrapping the bson_t pointer returned by a call to mongoc_cursor_next. However, the validity of this bson_t pointer is only until the next call to mongoc_cursor_next (see docs).

      Consider this example:

      auto cursor = db["fo"].find({});
      auto iter1 = cursor.begin();  // Calls mongoc_cursor_next().
      auto iter2 = cursor.begin();  // Calls mongoc_cursor_next().
      
      // At this point, iter1._doc violates the lifecycle constraints.
      
      iter1++;
      
      // At this point, iter2._doc violates the lifecycle constraints.
      

      In short, only the most recently iterated iterator ever has a valid bsoncxx::document::view.

            Assignee:
            david.golden@mongodb.com David Golden
            Reporter:
            david.golden@mongodb.com David Golden
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: