[CXX-2073] index_view::create_one should not check server reply "note" Created: 13/Jul/20  Updated: 30/Jun/23

Status: Backlog
Project: C++ Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Kevin Albertson Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CXX-2089 Use server error codes in place of er... Closed
Epic Link: C++ Error Improvements

 Description   

index_view::create_one() checks whether the server replies with a note indicating the index that the user tried to create already exists:

https://github.com/mongodb/mongo-cxx-driver/blob/d2dddbaa216b71d1c21db32c06422efdb0e24086/src/mongocxx/private/index_view.hh#L82-L83

if (result_view["note"] &&
    bsoncxx::string::to_string(result_view["note"].get_utf8().value) ==
        "all indexes already exist") {
    return bsoncxx::stdx::nullopt;
}

I assume the purpose is to signal to the user if they are trying to create an index that already exists.

But, similar to "ns not found" or other error message checks, I do not think we should rely on the exact value of the "note" string. If the server changes that note, the check will no longer be correct.

Furthermore, we may not need to check for index existence at all. The index management spec does not require we do. I do not know about every driver, but quickly checking pymongo shows that collection.create_index() always returns the index name, even if it exists.


Generated at Wed Feb 07 22:04:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.