Are couchdb views linked between two databases?

Let's say I have several databases on my couch instance (in my case, the user account database and the login database). Sessions have fields corresponding to a field in a user database. Is there a way to create a view or make a call that covers this correlation, or is it just to be done using an external script? To be more clear, here is an example.

Account db:
{
   "_id": "78555fdfdd345debf427373f9dfaeca4",
...
   "username" : "bob"
}

Sessions db:

{
   "_id": "78555fdfdd345debf427373f9dfcd7ae",
..
   "accountId": "78555fdfdd345debf427373f9dfaeca4",
   "username": "bob"
}

Is it possible to use emit or something similar to combine all this information into one call?

+5
source share
2 answers

, "type" .

...

Application db:
{
   "_id": "account.78555fdfdd345debf427373f9dfaeca4",
   "type": "account",
...
   "username" : "bob"
}

{
   "_id": "session.78555fdfdd345debf427373f9dfcd7ae",
   "type": "session",
..
   "accountId": "account.78555fdfdd345debf427373f9dfaeca4",
   "username": "bob"
}

:

map:
    function (doc) {
        if (doc.type=='account') {
            # ...
        }
    }
+5

, , .

, 1 , .

+3

All Articles