couchdb视图绑定在两个数据库之间? [英] couchdb views tied between two databases?

查看:83
本文介绍了couchdb视图绑定在两个数据库之间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的沙发实例上有几个数据库(在我的例子中是用户帐户数据库和登录会话数据库)会话具有与用户数据库中的字段对应的字段。有没有办法创建视图,或进行包含此关联的调用,还是只需要使用外部脚本?为了更清楚,这是一个例子。

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?

推荐答案

不,但常见的解决方法是为文档设置type属性。

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

例如.. 。

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') {
            # ...
        }
    }

这篇关于couchdb视图绑定在两个数据库之间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆