只投影数组对象中的元素

时间:2017-08-07 00:09:55

标签: mongodb mongoose

我试图在数组中投射一个字段。

例如,在下面的例子中

db.inventory.insertMany( [
  { item: "journal", status: "A", size: { h: 14, w: 21, uom: "cm" }, instock: [ { warehouse: "A", qty: 5 } ] },
  { item: "notebook", status: "A",  size: { h: 8.5, w: 11, uom: "in" }, instock: [ { warehouse: "C", qty: 5 } ] },
  { item: "paper", status: "D", size: { h: 8.5, w: 11, uom: "in" }, instock: [ { warehouse: "A", qty: 60 } ] },
  { item: "planner", status: "D", size: { h: 22.85, w: 30, uom: "cm" }, instock: [ { warehouse: "A", qty: 40 } ] },
  { item: "postcard", status: "A", size: { h: 10, w: 15.25, uom: "cm" }, instock: [ { warehouse: "B", qty: 15 }, { warehouse: "C", qty: 35 } ] }
]);

基于使用warehouse查找搜索,我需要item: "postcard列表的最终输出。

预期产出

["B", "C"]

更新

在我们的代码中,我需要为以下数据获取hashString的数组。 enter image description here

0 个答案:

没有答案