最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - couchdb views tied between two databases? - Stack Overflow

programmeradmin0浏览0评论

Say I have several databases on my couch instance (in my case a user account database and login session database) The sessions have fields corresponding to a field in the user database. Is there a way to create a view, or make a call that enpasses this correlation, or would it just have to be done with an external script? To be more clear, here's an example.

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

Sessions db:

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

Can I use emit or something like that to bundle together all this information in one call?

Say I have several databases on my couch instance (in my case a user account database and login session database) The sessions have fields corresponding to a field in the user database. Is there a way to create a view, or make a call that enpasses this correlation, or would it just have to be done with an external script? To be more clear, here's an example.

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

Sessions db:

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

Can I use emit or something like that to bundle together all this information in one call?

Share Improve this question asked Mar 24, 2011 at 16:50 V_HV_H 1,7933 gold badges34 silver badges59 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

No, however a mon workaround is to have a "type" attribute for documents.

For example...

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

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

And then in your views:

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

No, unfortunately there is no way to connect data from multiple databases.

Each view is supposed to be self-contained, otherwise updating any document in 1 database will immediately need to trigger views indexes in every other database to be recalculated in all cases.

发布评论

评论列表(0)

  1. 暂无评论