查询所有数组元素是否在另一个数组中

时间:2019-04-03 20:36:25

标签: mongodb mongoose

我想从一个数组中的所有元素都符合条件的集合中查询文档:名称字段和数量都应在“ currentStatus”数组中的minQuantity之内和之上。

在此示例中,我想检索文档_id:1和4

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},
]

0 个答案:

没有答案