Skip to content

CXX-2700 Add search index management e2e testing against Atlas #1002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions data/index-management/createSearchIndex.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
}
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down Expand Up @@ -100,7 +101,8 @@
}
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down
9 changes: 6 additions & 3 deletions data/index-management/createSearchIndexes.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"models": []
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down Expand Up @@ -87,7 +88,8 @@
]
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down Expand Up @@ -135,7 +137,8 @@
]
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down
3 changes: 2 additions & 1 deletion data/index-management/dropSearchIndex.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"name": "test index"
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down
9 changes: 6 additions & 3 deletions data/index-management/listSearchIndexes.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"name": "listSearchIndexes",
"object": "collection0",
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down Expand Up @@ -79,7 +80,8 @@
"name": "test index"
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down Expand Up @@ -119,7 +121,8 @@
}
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down
3 changes: 2 additions & 1 deletion data/index-management/updateSearchIndex.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"definition": {}
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down
20 changes: 15 additions & 5 deletions src/mongocxx/search_index_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ cursor search_index_view::list(const client_session& session,
return _get_impl().list(&session, name, options);
}

std::string search_index_view::create_one(bsoncxx::document::view_or_value definition) {
return create_one(search_index_model(definition));
}

std::string search_index_view::create_one(const client_session& session,
bsoncxx::document::view_or_value definition) {
return create_one(session, search_index_model(definition));
}

std::string search_index_view::create_one(bsoncxx::string::view_or_value name,
bsoncxx::document::view_or_value definition) {
return create_one(search_index_model(name, definition));
Expand All @@ -65,23 +74,24 @@ std::string search_index_view::create_one(const client_session& session,
return _get_impl().create_one(&session, model);
}

std::vector<bsoncxx::string::view_or_value> search_index_view::create_many(
std::vector<std::string> search_index_view::create_many(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into some issues with reading the values of the std::vector<bsoncxx::string::view_or_value> returned from this function due to ownership semantics. After talking to @eramongodb, we came to the conclusion that it would be easier and more clear to just make this a std::vector<std::string>. This minor change seen across this PR.

const std::vector<search_index_model>& models) {
auto response = _get_impl().create_many(nullptr, models);
return _create_many_helper(response["indexesCreated"].get_array().value);
}

std::vector<bsoncxx::string::view_or_value> search_index_view::create_many(
std::vector<std::string> search_index_view::create_many(
const client_session& session, const std::vector<search_index_model>& models) {
auto response = _get_impl().create_many(&session, models);
return _create_many_helper(response["indexesCreated"].get_array().value);
}

std::vector<bsoncxx::string::view_or_value> search_index_view::_create_many_helper(
std::vector<std::string> search_index_view::_create_many_helper(
bsoncxx::array::view created_indexes) {
std::vector<bsoncxx::string::view_or_value> search_index_names;
std::vector<std::string> search_index_names;
for (auto&& index : created_indexes) {
search_index_names.push_back(index.get_document().value["name"].get_string().value);
search_index_names.push_back(
bsoncxx::string::to_string(index.get_document().value["name"].get_string().value));
}
return search_index_names;
}
Expand Down
30 changes: 25 additions & 5 deletions src/mongocxx/search_index_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@ class MONGOCXX_API search_index_view {

///
/// @{
///
/// This is a convenience method for creating a single search index.
///
/// @param definition
/// The document describing the search index to be created.
///
/// @return The name of the created search index.
///
std::string create_one(bsoncxx::document::view_or_value definition);

///
/// This is a convenience method for creating a single search index.
///
/// @param definition
/// The document describing the search index to be created.
///
/// @return The name of the created search index.
///
std::string create_one(const client_session& session,
bsoncxx::document::view_or_value definition);

Copy link
Contributor Author

@joshbsiegel joshbsiegel Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two overloads were added due a change made in DRIVERS-2630 that allows for create_one to be called while only passing through a definition, no name. I kept the other overloads of create_one because the drivers ticket specified that a name should still be able to be passed through, but in the options of create_one. Because CXX allows function overloads, we don't have a need to have an "options" parameter.

///
/// This is a convenience method for creating a single search index.
///
Expand Down Expand Up @@ -151,8 +172,7 @@ class MONGOCXX_API search_index_view {
///
/// @return The names of the created indexes.
///
std::vector<bsoncxx::string::view_or_value> create_many(
const std::vector<search_index_model>& models);
std::vector<std::string> create_many(const std::vector<search_index_model>& models);

///
/// Creates multiple search indexes in the collection.
Expand All @@ -164,8 +184,8 @@ class MONGOCXX_API search_index_view {
///
/// @return The names of the created indexes.
///
std::vector<bsoncxx::string::view_or_value> create_many(
const client_session& session, const std::vector<search_index_model>& models);
std::vector<std::string> create_many(const client_session& session,
const std::vector<search_index_model>& models);

///
/// @}
Expand Down Expand Up @@ -232,7 +252,7 @@ class MONGOCXX_API search_index_view {

MONGOCXX_PRIVATE search_index_view(void* coll, void* client);

MONGOCXX_PRIVATE std::vector<bsoncxx::string::view_or_value> _create_many_helper(
MONGOCXX_PRIVATE std::vector<std::string> _create_many_helper(
bsoncxx::array::view created_indexes);

MONGOCXX_PRIVATE const impl& _get_impl() const;
Expand Down
2 changes: 2 additions & 0 deletions src/mongocxx/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ set(test_driver_sources
result/insert_one.cpp
result/replace_one.cpp
result/update.cpp
search_index_view.cpp
sdam-monitoring.cpp
spec/initial_dns_seedlist_discovery.cpp
spec/monitoring.cpp
Expand Down Expand Up @@ -337,6 +338,7 @@ set_dist_list (src_mongocxx_test_DIST
result/insert_one.cpp
result/replace_one.cpp
result/update.cpp
search_index_view.cpp
sdam-monitoring.cpp
spec/client_side_encryption.cpp
spec/command_monitoring.cpp
Expand Down
Loading