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

发布于 2024-10-25 12:25:34 字数 415 浏览 2 评论 0原文

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

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

Sessions db:

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

我可以使用emit或类似的东西将所有这些信息捆绑在一个调用中吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧情别恋 2024-11-01 12:25:34

不可以,但是常见的解决方法是为文档设置“类型”属性。

例如......

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

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') {
            # ...
        }
    }
谎言 2024-11-01 12:25:34

不,不幸的是,无法连接多个数据库中的数据。

每个视图都应该是独立的,否则更新 1 个数据库中的任何文档将立即需要触发每个其他数据库中的视图索​​引在所有情况下重新计算。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文