How does Simulating Joins works in Couchbase?

后端 未结 2 770
粉色の甜心
粉色の甜心 2021-01-13 20:01

I have documents one is dependent to other. first:

{
  \"doctype\": \"closed_auctions\",
  \"seller\": {
    \"person\": \"person11304\"
  },
  \"buyer\":          


        
2条回答
  •  野的像风
    2021-01-13 20:45

    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. 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.

提交回复
热议问题