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

index_view::create_one should not check server reply "note"

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: