Details
-
Improvement
-
Resolution: Works as Designed
-
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.