Mongodb 查询所有数组元素是否在另一个数组中
我想从一个集合中查询文档,其中数组中的所有元素都匹配一个条件:name字段和quantity都应该位于“currentStatus”数组中的minQuantity之内或之上 在本例中,我希望检索文档_id:1和4Mongodb 查询所有数组元素是否在另一个数组中,mongodb,mongoose,Mongodb,Mongoose,我想从一个集合中查询文档,其中数组中的所有元素都匹配一个条件:name字段和quantity都应该位于“currentStatus”数组中的minQuantity之内或之上 在本例中,我希望检索文档_id:1和4 Collection = [ { _id: 1, conditions: [ {name: 'product1', minQuantity: 30}, {name: 'product2', minQuantity: 10} ]
Collection = [
{
_id: 1,
conditions: [ {name: 'product1', minQuantity: 30},
{name: 'product2', minQuantity: 10} ]
},
{
_id: 2,
conditions: [ {name: 'product1', minQuantity: 50},
{name: 'product2', minQuantity: 10} ]
},
{
_id: 3,
conditions: [ {name: 'product1', minQuantity: 10},
{name: 'product2', minQuantity: 10},
{name: 'product3', minQuantity: 10} ]
}
{
_id: 4,
conditions: [ {name: 'product1', minQuantity: 10} ]
}
]
currentStatus = [
{name: 'product1', currentQuantity: 40},
{name: 'product2', currentQuantity: 20},
]