简体   繁体   English

couchdb视图绑定在两个数据库之间?

[英]couchdb views tied between two databases?

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 encompasses 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? 我可以使用emit或类似的东西在一次通话中将所有这些信息捆绑在一起吗?

No, however a common 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. 每个视图都应该是自包含的,否则更新1个数据库中的任何文档将立即触发所有其他数据库中的视图索​​引,以便在所有情况下重新计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM