Mongodb ';或';mongo db compass中的语句
在Mongodb罗盘中。我想在ownerName和ownerStreet属性中搜索集合中的单词“LLC”(我没有文本索引)。我从以下内容开始:Mongodb ';或';mongo db compass中的语句,mongodb,mongodb-compass,Mongodb,Mongodb Compass,在Mongodb罗盘中。我想在ownerName和ownerStreet属性中搜索集合中的单词“LLC”(我没有文本索引)。我从以下内容开始: {ownerName: {$regex: / LLC/i}} 它给出了3043个结果 但是,使用: {ownerName: {$regex: RegExp(' LLC')},ownerStreet: {$regex: RegExp(' LLC')}} 只给100 意思是这是一个“and”语句而不是“or” 如何在compass中使用“或”语句过滤器?
{ownerName: {$regex: / LLC/i}}
它给出了3043个结果
但是,使用:
{ownerName: {$regex: RegExp(' LLC')},ownerStreet: {$regex: RegExp(' LLC')}}
只给100
意思是这是一个“and”语句而不是“or”
如何在compass中使用“或”语句过滤器?您可以使用运算符
db.collection.find({
$or: [
{
ownerName: { $regex: RegExp(' LLC') }
},
{
ownerStreet: { $regex: RegExp(' LLC') }
}
]
})
你甚至可以把它简化为
db.collection.find({
$or: [
{
ownerName: / LLC/
},
{
ownerStreet: / LLC/
}
]
})