MongoDB Project Fields

通过Project可以返回指定的字段

[
  { 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 } ] }
]

返回doc
{ status: "A" }

{ status: "A" } and { item: 1, status: 1 }

{ status: "A" } and { item: 1, status: 1, _id: 0 }

{ status: "A" } and { status: 0, instock: 0 }

{ status: "A" } and { item: 1, status: 1, "size.uom": 1 }

{ status: "A" } and { "size.uom": 0 }

参考:
https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/

你可能感兴趣的:(mongodb,mongodb)