Join two types document in View

Hi ,
I have two ( or more) types of document, one for Account info like

{id,[....,Tag:"Account"]}

and next for transaction like

{id,[....,Tag:"Transaction"]}

now how can i create view to find any account’s transaction and also the summary of account’s transactions?

many thanks.

You cannot perform JOINs using Views.

maybe you can use map/reduce to join two types document in View.
FYI (P17)

Hi man,
I read documents and try below code but i encountered

Syntax error in the map function of the view `SubBa_Transactions’: SyntaxError: Unexpected token function (line 8:0)

error.

  if (doc.From_Account) {
    emit(doc.From_Account,[null,null,parseInt(doc.Transfered_Credit)]);
  } else if (doc.BankName && doc.BankCode) {
      emit(doc.Account,[doc.BankCode,doc.BankName,0]);
  }
}
function(keys, values, rereduce) {
  var BName
  var BCode
  var To_Credit=0
  if (rereduce) {
    for (var i=0;i<values.length;i++) {
      if (BankName) {  BName=BankName } 
      else if (BankCode) {BCode=BankCode } 
      else { To_Credit+=parseInt(doc.Transfered_Credit) }
    }
    return([BName,BCode,To_Credit]);
    }
}

coucl you please guide me?

Thanks.

you can write map function and reduce function in Couchbase admin console.[quote=“vhp1360, post:4, topic:9951”]
SyntaxError: Unexpected token function (line 8:0)
[/quote]

reduce function should not in map function.
I think the best way to join two type document is using N1QL.

i tried that here

regarding [quote=“atom_yang, post:5, topic:9951”]
I think the best way to join two type document is using N1QL.
[/quote]

as you know, View has himself index and i guessed it is more faster than N1ql, is not it?

Map function should be in the left. and reduce function should be in the right.

FYI

1 Like