Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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中返回true的任何条件的结果?_Mongodb - Fatal编程技术网

如何获得mongodb中返回true的任何条件的结果?

如何获得mongodb中返回true的任何条件的结果?,mongodb,Mongodb,myProductmongodb集合中的文档具有字段productName和productManufacturer。多个制造商可以生产具有相同产品名称的产品。我想进行一个查询,该查询接收以下格式的对象数组(只是一个示例): 并获得所有相关产品 到目前为止,我提出了以下问题: const products=wait Product.find({ $or:[ $and:[{'productName':'test1'},{'productManufacturer':'testManufacturer'

my
Product
mongodb集合中的文档具有字段
productName
productManufacturer
。多个制造商可以生产具有相同产品名称的产品。我想进行一个查询,该查询接收以下格式的对象数组(只是一个示例):

并获得所有相关产品

到目前为止,我提出了以下问题:

const products=wait Product.find({
$or:[
$and:[{'productName':'test1'},{'productManufacturer':'testManufacturer'}],
$and:[{'productName':'test2'},{'productManufacturer':'testManufacturer'}],
$and:[{'productName':'test3'},{'productManufacturer':'testManufacturer3'}]
]
})
根据mongodb

$or使用短路逻辑:运算结束后停止计算 遇到第一个真实的表情


因此,我不确定是否所有的
$和
表达式都将被计算。这是进行查询的正确方法吗?

@Minsky我不想根据制造商对产品进行分组。我只想返回一组找到的产品。@turivishal这个查询在我做的几个测试中确实有效,但我不确定这是偶然的还是正确的。由于引用了文档,我认为可能不会对所有的
$和
进行评估。您能否确认将对所有
$和
案例进行评估?如果是,这句话是什么意思?($或使用短路逻辑:操作遇到第一个真表达式后停止求值)您指的是运算符,但您需要在没有表达式文档的情况下指的是运算符,两者差别不大,我相信您已经解决了这一困惑带来的问题。@Turivshal您完全正确,我看错了文件的部分
[
{
  productName: 'test1',
  productManufacturer: 'testManufacturer'
},
{
  productName: 'test2',
  productManufacturer: 'testManufacturer'
},
{
  productName: 'test3',
  productManufacturer: 'testManufacturer3'
}
]