A simple wrapper of the class of MongoDB Client mongoc_client_t
.
More...
#include <db_mongoc.h>
|
| MongoClient (const char *host, vuint16_t port) |
| Constructor using IP address and port number. More...
|
|
| MongoClient (mongoc_client_t *conn) |
| Constructor using mongoc_client_t*.
|
|
| ~MongoClient () |
| Destructor.
|
|
void | Destroy () |
| Destroy explicitly.
|
|
mongoc_client_t * | GetConn () |
| Get mongoc_client_t instance.
|
|
mongoc_database_t * | GetDatabase (string const &dbname) |
| Get existing or newly created mongoc_database_t instance. More...
|
|
mongoc_collection_t * | GetCollection (string const &dbname, string const &collectionname) |
| Get mongoc_collection_t instance.
|
|
mongoc_gridfs_t * | GetGridFs (string const &dbname, string const &gfsname) |
| Get mongoc_gridfs_t instance.
|
|
MongoGridFs * | GridFs (string const &dbname, string const &gfsname) |
| Get MongoGridFs instance.
|
|
void | GetDatabaseNames (vector< string > &dbnames) |
| Get existing database names. More...
|
|
void | GetCollectionNames (string const &dbname, vector< string > &collnames) |
| Get collection names in MongoDB database. More...
|
|
void | GetGridFsFileNames (string const &dbname, string const &gfsname, vector< string > &gfs_exists) |
| Get GridFs file names in MongoDB database. More...
|
|
A simple wrapper of the class of MongoDB Client mongoc_client_t
.
◆ MongoClient()
ccgl::db_mongoc::MongoClient::MongoClient |
( |
const char * |
host, |
|
|
vuint16_t |
port |
|
) |
| |
Constructor using IP address and port number.
Get a client for a MongoDB instance using IP address and port number.
- Parameters
-
[in] | host | IP address, e.g., 127.0.0.1 |
[in] | port | Port number, the default is 27017 |
- Note
- The constructor should not be used directly, since it does not check the validation of IP address and the status of the database, and also without
mongoc_init()
. So, please use the alternative initialization usage, MongoClient *client = MongoClient::Init(host, port)
.
- See also
- MongoClient::Init()
◆ GetCollectionNames()
void ccgl::db_mongoc::MongoClient::GetCollectionNames |
( |
string const & |
dbname, |
|
|
vector< string > & |
collnames |
|
) |
| |
Get collection names in MongoDB database.
- Parameters
-
[in] | dbname | Database name string |
[in,out] | collnames | Collection names vector in the database |
◆ GetDatabase()
mongoc_database_t * ccgl::db_mongoc::MongoClient::GetDatabase |
( |
string const & |
dbname | ) |
|
Get existing or newly created mongoc_database_t
instance.
Databases are automatically created on the MongoDB server upon insertion of the first document into a collection. Therefore, there is no need to create a database manually.
◆ GetDatabaseNames()
void ccgl::db_mongoc::MongoClient::GetDatabaseNames |
( |
vector< string > & |
dbnames | ) |
|
Get existing database names.
- Parameters
-
[in,out] | dbnames | String vector of existing Database names |
◆ GetGridFsFileNames()
void ccgl::db_mongoc::MongoClient::GetGridFsFileNames |
( |
string const & |
dbname, |
|
|
string const & |
gfsname, |
|
|
vector< string > & |
gfs_exists |
|
) |
| |
Get GridFs file names in MongoDB database.
- Parameters
-
[in] | dbname | Database name |
[in] | gfsname | GridFS name |
[in,out] | gfs_exists | Existing GridFS file names |
◆ Init()
MongoClient * ccgl::db_mongoc::MongoClient::Init |
( |
const char * |
host, |
|
|
vuint16_t |
port |
|
) |
| |
|
static |
Initialization of MongoClient with the validation check of database.
- Check IP address
- Check database status
- Parameters
-
[in] | host | IP address, e.g., 127.0.0.1 |
[in] | port | Port number, the default is 27017 |
- Returns
- MongoClient instance
Examples:
if (nullptr == client) {
throw exception("MongoClient initialization failed!");
}
MongoClient(const char *host, vuint16_t port)
Constructor using IP address and port number.
Definition: db_mongoc.cpp:47
static MongoClient * Init(const char *host, vuint16_t port)
Initialization of MongoClient with the validation check of database.
Definition: db_mongoc.cpp:78
- See also
- MongoClient()
The documentation for this class was generated from the following files: