【问题标题】:mongodb: how to write $or clause with REmongodb:如何用 RE 编写 $or 子句
【发布时间】:2011-10-26 20:30:05
【问题描述】:

我想选择所有标题包含关键字或位置包含关键字的记录:

name_regex = ".*" + keyword + ".*";
name_reg = re.compile(name_regex,re.IGNORECASE)
search_dict["title"] = name_reg
search_dict["location"] = name_reg
records = collection.find(search_dict)

这将找到 $and 子句。如何指定 $or 子句?

【问题讨论】:

    标签: mongodb pymongo


    【解决方案1】:

    pymongo 等价于:

    db.collection.find({$or:[{title:name_reg}, {location:name_reg}]})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-21
      • 2012-01-01
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      • 2012-08-29
      • 2011-02-27
      相关资源
      最近更新 更多