Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CouchDB modeling for multi-user

I am already excited about document databases and especially about CouchDB's simplicity. But I have a hard time understanding if such databases are a viable option for multi user systems. Since those systems require some kind of relations between records which document databases do not provide.

Is it completely the wrong tool for such cases? Or some tagging and temporary views are the way to accomplish this? Or else...

UPDATE:
I understand the answers so far. But let me rephrase the question a bit. Lets say I have a load of semi-structured data which is normally a fit for CouchDB. I can tag them like "type=post" and "year=2008". My question is how far can I go with this type of tagging? Say can I create an array field with 10.000 names in it? Or is there a better way of doing this? It is a matter of understanding how to think in this document based sense.

like image 491
Bahadır Yağan Avatar asked Sep 29 '08 07:09

Bahadır Yağan


People also ask

Is CouchDB distributed?

CouchDB is a peer-based distributed database system.

Is CouchDB scalable?

Scalability. The architectural design of CouchDB makes it extremely adaptable when partitioning databases and scaling data onto multiple nodes. CouchDB supports both horizontal partitioning and replication to create an easily managed solution for balancing both read and write loads during a database deployment.

Is CouchDB document oriented?

Apache CouchDB is an open-source document-oriented NoSQL database, implemented in Erlang. CouchDB uses multiple formats and protocols to store, transfer, and process its data.

How can I speed up my CouchDB?

Using faster disks, striped RAID arrays and modern file systems can all speed up your CouchDB deployment.


1 Answers

There was a discussion on the mailing list awhile back that fits this question fairly well. The rule of thumb was to only store data in a document that is likely to change vs. grow. If the data is more likely to grow then you most likely want to store separate docs.

So in the case of a multi-user system one way of implementing ACL based permissions could be to create 'permission docs' that would be a mapping of user_id to doc_id with the appropriate permission indicated.

{
    _id: "permission_doc_1",
    type: "acl",
    user: "John",
    docid: "John's Account Info",
    read: true,
    write: true
}

And your views would be something along the lines of

function(doc)
{
    emit([doc.user, doc.docid], {"read": doc.read, "write": doc.write});
}

And given a docid and userid, checking for permissions would be:

http://localhost:5984/db/_view/permissions/all?key=["John", "John's Account Info"]

Obviously, this would require having some intermediary between the client and couch to make sure permissions were enforced.

like image 192
Paul J. Davis Avatar answered Sep 27 '22 22:09

Paul J. Davis