How to discover the storage engine
> db.serverStatus ().storageEngine
> db.runCommand({serverStatus: 1}).storageEngine
g ++ main .cpp - g3 - std = c ++ 14 - I /usr /include /mongocxx /v_noabi - I /usr /include /bsoncxx /v_noabi - I /usr /include /libbson - 1.0 - lbsoncxx - lmongocxx
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/uri.hpp>
#include <bsoncxx/json.hpp>
#include <bsoncxx/types.hpp>
#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>
#include <iostream>
/**
* this code was written to discover which storage engine the mongodb instance
* is using
*/
int main (int argc , char * * argv )
{
if (argc < 2 )
{
std ::cout << "[bin] [dbName]" << std ::endl ;
return 1 ;
}
try
{
std ::string dbName (argv [1 ]);
mongocxx ::instance instance {};
mongocxx ::client conn { mongocxx ::uri {} };
auto db = conn [dbName ];
// server status
auto serverStatusComm = bsoncxx ::builder ::basic ::document {};
serverStatusComm .append (bsoncxx ::builder ::basic ::kvp ("serverStatus" , 1 ));
auto resp = db .run_command (serverStatusComm .view ()).view ();
auto engine = resp ["storageEngine" ];
std ::string engineName (engine ["name" ].get_utf8 ().value );
// print storageEngine document
std ::cout << bsoncxx ::to_json (engine ) << std ::endl ;
std ::cout << "This instance is running with '" ;
std ::cout << engineName << "' storage engine" << std ::endl ;
}
catch (const std ::exception & e )
{
std ::cout << e .what () << std ::endl ;
}
}