mongocxx::uri uri("XXX");
|
mongocxx::client client(uri);
|
bsoncxx::oid id;
|
std::string name = id.to_string();
|
mongocxx::database db = client[name];
|
mongocxx::options::create_collection opt;
|
opt.capped(true).size(10000).max(3);
|
mongocxx::collection col = db.create_collection(name,opt);
|
bsoncxx::builder::stream::document insert { };
|
int n = 13;
|
for (int i = 0; i < n; i++) {
|
insert << "CollectionTest::CreateCappedCollection" << "ok"
|
<< "capped_id" << id;
|
col.insert_one(insert.view());
|
insert.clear();
|
}
|
bsoncxx::builder::stream::document docFind { };
|
mongocxx::options::find optFind;
|
optFind.cursor_type(mongocxx::cursor::type::k_tailable);
|
mongocxx::cursor cursor = col.find(docFind.view(),optFind);
|
ASSERT_TRUE(cursor.begin() != cursor.end());
|
int m = 0;
|
for (auto doc : cursor){
|
m++;
|
}
|
ASSERT_EQ(3,m);
|
insert << "CollectionTest::CreateCappedCollection" << "ok"
|
<< "capped_id" << id;
|
col.insert_one(insert.view());
|
ASSERT_TRUE(cursor.begin() != cursor.end());
|
for (auto doc : cursor){
|
m++;
|
}
|
ASSERT_EQ(4,m);
|