我的集合有 1000 个字段,我想排除与特定正则表达式匹配的字段。数百个字段的形式为:'labelXXXX',其中 XXXX 是 4 个整数。这可能吗?
(即,如何从集合中排除与查询中的“labelXXXX”匹配的字段?)
最佳答案
我通过在 mongodb 中使用 $not 解决了这个问题
{
"_id" : "1",
"name" : "label123"
}
/* 2 */
{
"_id" : "2",
"name" : "sample"
}
db.getCollection('things').find({name:{$not:/^label/}})
Output:{ "_id" : "2", "name" : "sample" }
关于mongodb - 基于正则表达式排除 Mongo 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46308744/