Nested Databases in CouchDB

It seems you cannot embed databases in CouchDB. How do people deal with this limitation? For example, suppose I want to create a blogging mechanism in which each domain has a separate database. In each database, I may need the Users database, Orders database, etc., to contain various user documents, order documents, etc.

The obvious way is a flat structure in which the database name demarcates the artificial boundary between the nesting levels of the database with a hyphen:

myblog.com-users
myblog.com-posts
myblog.com-comments
anotherblog.com-users
anotherblog.com-posts
anotherblog.com-comments
...hundreds more...

Another solution would be to keep the databases at a lower level and mark each document with a top-level value:

user document containing User1 with instance = "Test" or field = "myblog.com"

+3
source share
2 answers

I think you are using the term database here. There is no reason why you cannot store user, post and comment data in the same couchdb database. Your couchdb views can extract user documents from message documents, from comment documents.

An example map function for user documents in the couchdb database:

function(doc) {
  if (doc.type = 'user') { // only return user documents
     emit([doc.domain, doc.id], doc); // the returned docs will be sorted by domain
  }
}

see Api Browsing for ways to limit the results of views by domain using a start key and an endpoint with sorting views.

+6
source

, , , .

+3

Source: https://habr.com/ru/post/1721892/


All Articles