Skip to content

Commit

Permalink
clean up sample code
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-mack committed Jan 9, 2025
1 parent 62dbacf commit e64dba6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions source/includes/authentication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ auto client = mongocxx::client(uri);

// start-auth-err
try {
auto uri = mongocxx::uri("mongodb://<db_username>:<db_password>@<hostname>:<port>/?"
"authSource=admin&authMechanism=SCRAM-SHA-256");
auto uri = mongocxx::uri("<Your chosen auth method>");
auto client = mongocxx::client(uri);
client["db"].run_command(bsoncxx::from_json(R"({"ping": 1})")); // Any command requiring authorization

client["db"].run_command("<Any command requiring authorization>");

} catch (const mongocxx::exception& ex) {
std::cerr << "Error: " << ex.what() << std::endl;
}
Expand Down

0 comments on commit e64dba6

Please sign in to comment.