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 someth开发者_高级运维ing like that to bundle together all this information in one call?
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.
精彩评论