Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb ';或';mongo db compass中的语句_Mongodb_Mongodb Compass - Fatal编程技术网

Mongodb ';或';mongo db compass中的语句

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中使用“或”语句过滤器?

在Mongodb罗盘中。我想在ownerName和ownerStreet属性中搜索集合中的单词“LLC”(我没有文本索引)。我从以下内容开始:

{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/
    }
  ]
})