从其他文档中获取详细信息

fetch details from other documents

假设我设计了一个用于在酒吧接受订单的 couchdb 应用程序。 我有一个包含产品和订单的数据库。

产品看起来像:

{ _id: "beer", type: "product", price: 5 }
{ _id: "juice", type: "product", price: 2 }

订单如下所示:

{ _id: "order for table 1", type: "order", items: { "beer": 1, "juice": 4 } }

在这里,table 1 订购了 1 瓶啤酒4 瓶果汁.

我想创建一个设计文档,输出类似

的内容
{
  _id: "order for table 1",
  items: {
    beer: {
      price: 5,
      quantity: 1
    },
    juice: {
      price: 2,
      quantity: 4
    }
  }
}

地图功能是什么样的?

这可以通过 map-side 连接实现,如果您的 product JSON 是小型数据集。一个可能的逻辑:

1) Use the product file as static input to the mapper. Use `DistributedCahe` or alternatively you may add a big `JSON` object consisting of all the products into the context.

2) In the Mapper, make sure that one order is input to the mapper. Using `product` file from `DistributedCahe` (or `product` JSON from the context); create your output JSON and write to context.

3) You do not need a reducer here.