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

list_collections exception thrown only on cursor iteration

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Works as Designed
    • Icon: Minor - P4 Minor - P4
    • None
    • None
    • None
    • None

    Description

      The database::list_collections() function returns a cursor. The only way to detect an error from this query is to begin iterating on the cursor with cursor::begin(). That is, the following code fragment will go to the catch part: 

      auto cursor = db.list_collections(make_document(kvp("$invalidFilter", 1)));
      std::cerr << "Cursor creation OK\n";
      try {
          auto it = cursor.begin();
      } catch (mongocxx::query_exception e) {
          std::cerr << "Query failed. Exception: " << e.what() << "\n";
      }
      

      Should this be the way the failed query is detected? It could potentially seem misleading that a cursor was instantiated without a problem, but then using it throws an exception.

      One way to alter this is adding an error-related public member to the cursor class for the client to access, but that may complicate the interface a bit.

      Attachments

        Activity

          People

            jesse@mongodb.com A. Jesse Jiryu Davis
            evgeni.dobranov@mongodb.com Evgeni Dobranov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: