Skip to content

Commit

Permalink
ADD nameOnly to listDatabase command on MongoDB
Browse files Browse the repository at this point in the history
  • Loading branch information
fgalan committed Mar 7, 2024
1 parent d7793bc commit 17740ee
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix: lighter operation to get databases list from MongoDB (#4517)
1 change: 1 addition & 0 deletions src/lib/mongoBackend/MongoGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ bool getOrionDatabases(std::vector<std::string>* dbsP)

orion::BSONObjBuilder bob;
bob.append("listDatabases", 1);
bob.append("nameOnly", true);

if (!orion::runDatabaseCommand("admin", bob.obj(), &result, &err))
{
Expand Down
9 changes: 4 additions & 5 deletions src/lib/mongoDriver/mongoConnectionPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,21 @@ static int pingConnection(mongoc_client_t* conn, const char* db, bool mtenat)
// ping will be listDatabases in the admin DB. But if we run in not mtenant
// mode listCollections in the default database will suffice

std::string cmd;
std::string effectiveDb;

bson_t* ping = bson_new();
if (mtenat)
{
cmd = "listDatabases";
BSON_APPEND_INT32(ping, "listDatabases", 1);
BSON_APPEND_BOOL(ping, "nameOnly", true);
effectiveDb = "admin";
}
else
{
cmd = "listCollections";
BSON_APPEND_INT32(ping, "listCollections", 1);
effectiveDb = db;
}

bson_t* ping = bson_new();
BSON_APPEND_INT32(ping, cmd.c_str(), 1);
mongoc_database_t* database = mongoc_client_get_database(conn, effectiveDb.c_str());

bson_error_t error;
Expand Down

0 comments on commit 17740ee

Please sign in to comment.