【问题标题】:How to use conditional operators in mongodb queries in c++如何在 C++ 中的 mongodb 查询中使用条件运算符
【发布时间】:2011-12-06 23:52:00
【问题描述】:

在使用 MongoDB C++ 驱动程序时,我没有找到如何在查询中使用条件运算符 ("$in", "$gt", "$lt"...)

javascript 实现示例:

db.collection.find( { field : { $in : array } } );
db.collection.find( { "field" : { $gt: value1, $lt: value2 } } );

编辑:C++ documentation 回答 $gt/$lt 运算符,但对 $in 只字未提:

【问题讨论】:

    标签: c++ mongodb conditional-operator


    【解决方案1】:

    也许我误解了,但您问题中的链接实际上确实举了一个例子。表中的第六项显示了 javascript 和 C++ 驱动程序之间的以下关系:

    Javascript

    db.users.find({'age':{$gt:33},{$lte:40}})
    

    C++

    auto_ptr<DBClientCursor> cursor = 
      c.query("mydb.users", QUERY("age"<<GT<<33<<LTE<<40));
    

    【讨论】:

    • 没错,我不知道为什么我在我的问题中添加了 $gt/$lt。我的问题是 $in 运算符。
    猜你喜欢
    • 2023-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多