本文整理汇总了C++中mongo::DBClientConnection::connect方法的典型用法代码示例。如果您正苦于以下问题:C++ DBClientConnection::connect方法的具体用法?C++ DBClientConnection::connect怎么用?C++ DBClientConnection::connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongo::DBClientConnection
的用法示例。
在下文中一共展示了DBClientConnection::connect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
mongo::DBClientConnection &getInstance() {
static mongo::DBClientConnection instance;
static bool ran = false;
if(!ran) {
ran = true;
#ifdef __APPLE__
instance.connect("localhost");
#else
instance.connect(MONGO_IP);
std::string errmsg;
instance.auth(MONGO_SOURCE, MONGO_USER, MONGO_PASSWORD, errmsg);
#endif
}
return instance;
}
示例2: while
int
main(int argc, char *argv[]) {
int opt;
const char *optstr = "m:f:h";
const char *mongo_server = "localhost:27017";
string errmsg;
while ((opt = getopt(argc, argv, optstr)) != -1) {
switch (opt) {
case 'm':
mongo_server = optarg;
break;
case 'f':
dns_server = optarg;
break;
case 'h':
default:
print_usage(argv[0]);
return 0;
}
}
if (! mongo_conn.connect(mongo_server, errmsg)) {
cerr << errmsg << endl;
return -1;
}
resolve_soa();
return 0;
}
示例3: dashboard_conn_check
void dashboard_conn_check(std::string cloud_name) {
if(!msattrs) {
APIDictionary result(perform("cldshow", cloud_name, "metricstore"));
host = APIString(result["hostname"]);
port = APIString(result["port"]);
msci.connect(host + ":" + port + "/metrics");
result = APIDictionary(perform("cldshow", cloud_name, "time"));
username = APIString(result["username"]);
msattrs = 1;
}
}
示例4: host
mongo::DBClientConnection& GetDB() {
if(!connected) {
std::string host(GetConfig().GetAttribute("Database.host").ToString());
LOGINFO("正在连接到 " + host + " 的 mongodb 服务器");
try {
dbconnection.connect(host);
connected = true;
LOGINFO("已连接");
} catch(mongo::DBException &e) {
LOGERROR("连接数据库时发生错误: " + e.toString());
throw FCException("无法连接至数据库");
}
}
return dbconnection;
}
示例5: getConnection
bool MongoDBDriver::getConnection(mongo::DBClientConnection &conn) {
Uri u = Uri::Parse(url);
int p=-1; // default
if (!u.Port.empty()) {
try {
p = stoi(u.Port,nullptr,10);
} catch(...) {
}
}
mongo::HostAndPort hp(u.Host,p);
std::string errmsg = url;
return(conn.connect(hp,errmsg));
}