0
我一直在試圖拉出數據庫中存在的所有集合的列表並嘗試使用: cursor list_collections(bsoncxx :: document :: view filter = {});列出使用mongocxx的所有數據庫集合
但無法迭代集合。
任何人都可以幫助我嗎?
我一直在試圖拉出數據庫中存在的所有集合的列表並嘗試使用: cursor list_collections(bsoncxx :: document :: view filter = {});列出使用mongocxx的所有數據庫集合
但無法迭代集合。
任何人都可以幫助我嗎?
得到了答案:
int main(int, char**)
{
mongocxx::instance inst{};
mongocxx::client conn{mongocxx::uri{}};
// auto collection = conn["test"]["restaurants"];
mongocxx::database db = conn["test"];
auto cursor1 = db.list_collections();
for (const bsoncxx::document::view& doc :cursor1)
{
bsoncxx::document::element ele = doc["name"];
std::string name = ele.get_utf8().value.to_string();
std::cout <<name<< std::endl;
}
}