模拟联接在Couchbase中如何工作? [英] How does Simulating Joins works in Couchbase?

查看:58
本文介绍了模拟联接在Couchbase中如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件,一个文件依赖于另一个文件。首先:

I have documents one is dependent to other. first:

{
  "doctype": "closed_auctions",
  "seller": {
    "person": "person11304"
  },
  "buyer": {
    "person": "person0"
  },
  "itemref": {
    "item": "item1"
  },
  "price": 50.03,
  "date": "11/17/2001",
  "quantity": 1,
  "type": "Featured",
  "annotation": {
    "author": {
      "person": "person8597"
    }
}

在这里您可以看到doc.buyer.person依赖于另一个这样的文档:

here you can see doc.buyer.person is dependent to another documents like this:

{
  "doctype": "people",
  "id": "person0",
  "name": "Kasidit Treweek",
  "profile": {
    "income": 20186.59,
    "interest": [
      {
        "category": "category251"
      }
    ],
    "education": "Graduate School",
    "business": "No"
  },
  "watch": [
    {
      "open_auction": "open_auction8747"
    }
  ]
}

如何从这两个文件中获得买家的名字?我的意思是doc.buyer.person与第二个文档的ID相关联。这是联接,从文档中还不清楚。 http://docs.couchbase.com/couchbase-manual- 2.0 /#solutions-for-simulation-joins

How can I get buyer's name from these two documents? I means doc.buyer.person is connected with second document's id. It is join and from documentation it's not clear. http://docs.couchbase.com/couchbase-manual-2.0/#solutions-for-simulating-joins

推荐答案

首先,让我指出您引用的文档部分的第一句话说(我强调了一点):

Well, first off, let me point out that the very first sentence of the documentation section that you referenced says (I added the emphasis):


数据之间的联接 ,即使将要检查的文档包含在同一存储桶中的
中,也无法直接在
视图系统中使用

Joins between data, even when the documents being examined are contained within the same bucket, are not possible directly within the view system.

因此,对您问题的快速回答是,您有很多选择。以下是其中的一些:

So, the quick answer to your question is that you have lots of options. Here are a few of them:


  1. 假设您只需要为一小部分人提供姓名。创建一个视图,将PersonId作为键输出,将Name作为值输出,然后每次需要时在视图中查询一个特定的名称。

  2. 假定您需要很多人参加很多拍卖。从#1下载基本索引的全部内容,并使用linq执行连接。

  3. 假定您需要此人的许多属性,而不仅仅是姓名。下载每个拍卖项目的人员文档。

  4. 假定您需要拍卖和人员中的一小部分。为每个需要的字段建立索引,包括一个类型字段,并在人员键下发出所有这些字段。您将能够在视图中查询属于该人的所有项目。

  1. Assume you need only the name for a rather small subset of people. Create a view that outputs the PersonId as key and Name as value, then query the view for a specific name each time you need it.
  2. Assume you need many people joined to many auctions. Download the full contents of the basic index from #1 and execute the join using linq.
  3. Assume you need many properties of the person, not just the name. Download the Person document for each auction item.
  4. Assume you need a small subset from both Auction and People. Index the fields from each that you need, include a type field, and emit all of them under the key of the Person. You will be able to query the view for all items belonging to the person.

在链接到的示例中使用了最后一种方法在你的问题。为了提高性能,有必要针对您的使用情况量身定制方法。

The last approach was used in the example you linked to in your question. For performance, it will be necessary to tailor the approach to your usage scenario.

这篇关于模拟联接在Couchbase中如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆