list_collections exception thrown only on cursor iteration

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Works as Designed
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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.

            Assignee:
            A. Jesse Jiryu Davis
            Reporter:
            Evgeni Dobranov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: