N1ql join query with different key name

Hi Team,

I want to perform join on couchbase bucket. I have following scenario.

  1. I want to perform join on same bucket with different type of documents.
  2. Key variable which i will use for join is different in both document.
    e.g. doc1 : “messageId”: “12345”
    doc2: “paymentId” : “12345”
  3. Id is also different on which I cannot perform join.

I want to get doc2 details from doc1 whose common field is mentioned above.
Above value will remain same for both document but name will be different. I want to fetch “messageName” , “paymentId”, and “test” (Please see below sample documents)

I tried finding solutions and all possible queries, but no success.
Could you please provide proper and optimized solution for this?

Sample Doc 1
{
“paymentId”: “12345”,
“test”: “test data”
}

Sample Docs 2
{
“messageId”: “12345”,
“messageName” : “ABC”
}

One way you can do this is with the new ANSI join feature available in Couchbase Server 5.5. You can simply join on the fields you want. Read more about it here: https://blog.couchbase.com/new-querying-features-couchbase-server/