-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* (DOCSP-40808) Added atlas page based on PHP docs. * (DOCSP-40808) Replace php command names with cpp * (DOCSP-40808) Edits. * (DOCSP-40808) Added copyable to examples in replace page, and edited example for atlas search indexes. * (DOCSP-40808) Edits. * (DOCSP-40808) Edits. * (DOCSP-40808) Edits. * (DOCSP-40808) Edits. * (DOCSP-40808) Edits. * (DOCSP-40808) Edits. * (DOCSP-40808) Edits. * (DOCSP-408088) Added multiple index example. * (DOCSP-40808) Pull changes to compound and single indexes, add changes to index code examples file. * (DOCSP-40808) Build error fixes. * (DOCSP-40808) Build error fixes. * (DOCSP-40808) Edits. * (DOCSP-40808) Reorganizing section introductions. * (DOCSP-40808) Reorganizing section introductions. * (DOCSP-40808) edits. * (DOCSP-40808) Added example for listing one search index. * (DOCSP-40808) Add examples for delete and update a search index. * (DOCPS-40808) Fixing build errors. * (DOCSP-40808) Reorganizing text. * (DOCSP-40808) Reorganizing text. * (DOCSP-40808) Reorganizing text. * (DOCSP-40808) Added API links * (DOCSP-40808) Output edit. * (DOCSP-40808) Updates. * (DOCSP-40808) Updates. * (DOCSP-40808) Fix page reference. * (DOCSP-40808) Breaking up the create an index section and adding text to indexes landing page. * (DOCSP-40808) Added code examples to indexes landing page. * (DOCSP-40808) Note to tip * (DOCSP-40808) De-wordi-fication. * (DOCSP-40808) Fix reference. * (DOCSP-40808) Replace delete with remove * (DOCSP-40808) Added note. * (DOCSP-40808) Add new links and reorganize. * (DOCSP-40808) Add new links and reorganize. * (DOCSP-40808) Added code comment. * (DOCSP-40808) Standardizing directions. * (DOCSP-40808) range based vs iterator * (DOCSP-40808) range-based * (DOCSP-40808) Edits. * (DOCSP-40808) Simplify the list indexes. * (DOCSP-40808) Error fix. * (DOCSP-40808) Note to important. * (DOCSP-40808) Edits. * (DOCSP-40808) Editing output. * (DOCSP-40808) Editing output. * (DOCSP-40808) Editing output. * (DOCSP-40808) Editing output. * (DOCSP-40808) Make output consistent. * (DOCSP-40808) Fix updated code. * (DOCSP-40808) Remove comments. * (DOCSP-40808) Fix build errors. * (DOCSP-40808) Edits. * (DOCSP-40808) Edits. * (DOCSP-40808) Fix code examples. * (DOCSP-40808) Edits. * (DOCSP-40808) Remove create multiple search indexes * (DOCSP-40808) Final edits. * (DOCSP-40808) @mongoKart Review changes. * (DOCSP-40808) @mongoKart Review edits: Adding more context to create a search index. * (DOCSP-40808) @mongoKart Review changes: more context for create a single dynamic index. * (DOCSP-40808) @mongoKart Replace all 'search index' with 'atlas search index' * (DOCSP-40808) @mongoKart Addressing feedback for create an index. * (DOCSP-40808) @mongoKart addressing feedback. * (DOCSP-40808) Addressing review feedback. * (DOCSP-40808) @mongoKart Feedback changes. * (DOCSP-40808) Removed text about Atlas Search Queries because it is covered in the overview. * (DOCSP-40808) @mongoKart Editing directions to create a new index. * (DOCSP-40808) Edit. * (DOCSP-40808) Link error fix. * (DOCSP-40808) @mongoKart reorganizing the create_one() directions. * (DOCSP-40808) Fix formatting in bulleted list. * (DOCSP-40808) Typo. * (DOCSP-40808) @mongoKart Addressing feedback. * (DOCSP-40808) @mongoKart Addressing feedback. * (DOCSP-40808) Fix ambiguous wording. * (DOCSP-40808) @kevinAlbs Review changes.
- Loading branch information
Showing
7 changed files
with
555 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,91 @@ | ||
// start-single-field | ||
auto index_specification = make_document(kvp("<field name>", 1)); | ||
auto result = collection.create_index(index_specification.view()); | ||
/* | ||
To build: | ||
brew install mongo-cxx-driver | ||
clang++ -o indexes main.cpp -std=c++17 $(pkg-config --libs --cflags libmongocxx) | ||
*/ | ||
#include <iostream> | ||
|
||
std::cout << "Index created: " << bsoncxx::to_json(result) << std::endl; | ||
// end-single-field | ||
#include <bsoncxx/builder/basic/document.hpp> | ||
#include <bsoncxx/json.hpp> | ||
#include <mongocxx/client.hpp> | ||
#include <mongocxx/instance.hpp> | ||
#include <mongocxx/uri.hpp> | ||
|
||
// start-compound-field | ||
auto index_specification = make_document(kvp("<field name 1>", -1), kvp("<field name 2>", -1)); | ||
auto result = collection.create_index(index_specification.view()); | ||
using bsoncxx::builder::basic::kvp; | ||
using bsoncxx::builder::basic::make_document; | ||
|
||
std::cout << "Index created: " << bsoncxx::to_json(result) << std::endl; | ||
// end-compound-field | ||
int main() { | ||
|
||
// start-remove-index | ||
collection.indexes().drop_one("<index name>"); | ||
mongocxx::instance instance; | ||
mongocxx::uri uri("<connectionString>"); | ||
mongocxx::client client(uri); | ||
|
||
std::cout << "Index dropped." << std::endl; | ||
// end-remove-index | ||
auto db = client["<databaseName>"]; | ||
auto collection = db["<collectionName>"]; | ||
|
||
{ | ||
// start-single-field | ||
auto index_specification = make_document(kvp("<fieldName>", 1)); | ||
auto result = collection.create_index(index_specification.view()); | ||
|
||
// start-remove-all-indexes | ||
collection.indexes().drop_all(); | ||
std::cout << "Index created: " << bsoncxx::to_json(result) << std::endl; | ||
// end-single-field | ||
} | ||
{ | ||
// start-compound-field | ||
auto index_specification = make_document(kvp("<fieldName1>", -1), kvp("<fieldName2>", -1)); | ||
auto result = collection.create_index(index_specification.view()); | ||
|
||
std::cout << "All indexes removed." << std::endl; | ||
// end-remove-all-indexes | ||
std::cout << "Index created: " << bsoncxx::to_json(result) << std::endl; | ||
// end-compound-field | ||
} | ||
{ | ||
// start-remove-index | ||
collection.indexes().drop_one("<indexName>"); | ||
|
||
std::cout << "Index dropped." << std::endl; | ||
// end-remove-index | ||
|
||
// start-remove-all-indexes | ||
collection.indexes().drop_all(); | ||
|
||
std::cout << "All indexes removed." << std::endl; | ||
// end-remove-all-indexes | ||
} | ||
{ | ||
// start-create-search-index | ||
// Create an index model with your index name and definition | ||
auto siv = collection.search_indexes(); | ||
auto name = "<searchIndexName>"; | ||
auto definition = make_document(kvp("mappings", make_document(kvp("dynamic", true)))); | ||
auto model = mongocxx::search_index_model(name, definition.view()); | ||
|
||
// Create the search index | ||
auto result = siv.create_one(model); | ||
std::cout << "New index name: " << result << std::endl; | ||
// end-create-search-index | ||
} | ||
{ | ||
// start-list-search-indexes | ||
auto siv = collection.search_indexes(); | ||
auto result = siv.list(); | ||
for (const auto &idx : result) { | ||
std::cout << bsoncxx::to_json(idx) << std::endl; | ||
} | ||
// end-list-search-indexes | ||
} | ||
{ | ||
// start-update-search-index | ||
auto siv = collection.search_indexes(); | ||
auto update_fields = make_document(kvp("<fieldName>", make_document(kvp("type", "<fieldType>")))); | ||
auto update_definition = make_document(kvp("mappings", make_document(kvp("dynamic", false), kvp("fields", update_fields)))); | ||
siv.update_one("<searchIndexName>", update_definition.view()); | ||
// end-update-search-index | ||
} | ||
{ | ||
// start-remove-search-index | ||
auto siv = collection.search_indexes(); | ||
siv.drop_one("<searchIndexName>"); | ||
// end-remove-search-index | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.