2015-03-18 41 views
1

我创建了一个客户端,需要从数据库中读取和处理数据。Mongodb C驱动程序,测试服务器是否运行?

我已经意识到,我不能测试我用mongoc_client_new创建的连接,只要测试它是否为null,因为驱动程序使用延迟连接。

如何测试数据库是否真的启动并运行?也许搜索数据库时没有添加任何查询条件?

我试过了get_collection_count,但是吐出-1是否数据库正在运行。

回答

2

我认为mongoc_client_get_server_status可以给出信息。

 bson_t reply; 
     bson_error_t error; 
     if(mongoc_client_get_server_status(client, nullptr, &reply, &error)) { 
     bson_iter_t iter; 
     assert(bson_iter_init_find (&iter, &reply, "ok")); 
     } 
     bson_destroy(&reply); 
相关问题