Match any couchdb design key

I'm new to couchdb, I have a two-key design. I use node to list view. In any case, I can only pass one key from node and if it matches either of the two keys from couchdb and gets the result.

My design in couchdb:

function(doc) {
if(doc.doc_type==="messages")
  emit([doc.from, doc.to], doc);
}

Passing a key using node

db.view('message','fetch_msg',{key:"user1"}, function(err, body) {      
    if(err)console.log(JSON.stringify(err))
        console.log(body.rows.length)
    console.log(JSON.stringify(body));
})

Like "user1", this is one of the keys. message / fetch_msg is my design.

Any help would be appreciated.

+4
source share
2 answers

You can emit several keys for each document - each key will return the same document.

function (doc) {
  if (doc.doc_type !== 'messages')
    return

  emit(doc.from, null)
  emit(doc.to, null)
}

, . ?include_docs=true , .

0

, - this. {} . ["user1", {}] [{}, "user1"]. , endkey couchdb .

0

All Articles