【发布时间】:2013-12-09 02:52:10
【问题描述】:
我可以通过pymongo 使用 SQL Like 运算符,
db.test.find({'c':{'$regex':'ttt'}})
但是如何使用Not Like 运算符呢?
我试过了
db.test.find({'c':{'$not':{'$regex':'ttt'}})
但出现错误:
OperationFailure: $not 不能有正则表达式
【问题讨论】:
-
我知道这有点晚了,但在 MongoDB 4.2 中,
$not和$regex运算符的组合似乎对我有用。 -
db.collectionname.find( { column: { $not: /^ttt$/ } } )这很简单。 -
$not和$regex从 MongoDB 4.0.7 开始可以一起使用。 -
@Milan 是的,这很容易,因为它是 8 年前作为答案发布的。您的评论没有帮助。
标签: regex mongodb mongodb-query pymongo sql-like