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

Having more than one iterator per cursor violates mongoc lifecycle constraints

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 3.1.0
    • None
    • Implementation
    • None
    • Major Change

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: