int main()
{
mongocxx::instance instance{}; // This should be done only once.
mongocxx::client client(mongocxx::uri("mongodb://192.168.1.100:37017"));
mongocxx::database db = client["logDB"];
mongocxx::collection coll = db["order_record"];
// 查询最近10天记录
int64_t seconds = 10 * 24 * 60 *60;
auto query_value = document{}
<< "time" << open_document << "$gte" << bsoncxx::types::b_date(chrono::system_clock::now() - std::chrono::seconds(seconds)) << close_document
<< "orderid" << 1000001 << finalize;
mongocxx::cursor cursor = coll.find(query_value.view());
int32_t icount = 0;
for (auto &doc : cursor)
{
LOG_INFO << "[" << icount <<"] orderid:" << doc["orderid"].get_int64();
LOG_INFO <
MongoDB查询一段时间数据(c++)
最新推荐文章于 2022-04-05 15:36:30 发布
本文介绍如何使用C++ SDK在MongoDB中查询指定时间段内的数据,涵盖连接数据库、构建时间条件查询语句及解析结果等关键步骤。
摘要由CSDN通过智能技术生成