如何在mongodb中得到复杂where子句的否定性

时间:2013-01-11 07:35:16

标签: pymongo

我有一个动态生成的mongo db complex过滤器,可能看起来像

where_condition = {"$and":[{"column_3": "Offer"}, {"column_2":"MSN"}]}
collection.find(where_condition)

条件可能在$and$or

中具有未知深度

是否有可能找到where_condition

的否定

这不起作用

not_condition = {"$not": where_condition}

1 个答案:

答案 0 :(得分:0)

你会想要使用$ nor。像这样:

where_condition = {"$and":[{"column_3": "Offer"}, {"column_2":"MSN"}]}
not_condition = {"$nor":[{"column_3": "Offer"}, {"column_2":"MSN"}]}

您可以在$nor的mongodb文档中找到更多信息。