问题
I would like to restrict the user permissions so that a normal user is only able to read/write its own user document.
I managed to set the write permissions such that a user can only edit their own document (via the validate_doc_update function in the design document).
Now I only have to limit a user from viewing the user list or other user documents. If I set the database read permissions to the '_admin' role, then the user will not be able to view their own document, which it's not what I intend.
Can this be done in a more general way? I.e. to set read permissions such that a user is able to read only some specific documents in the database?
回答1:
Unfortunately, per-document read control is not possible.
However, if you use a list function
you can perform a "post-query filter" that limits the results of a view query based on the current session user. (via the userCtx
parameter)
回答2:
In CouchDB creating a new database is cheap and it was designed to keep the data as close as possible to the user who needs it. So the suggested approach is to have one database for each user.
来源:https://stackoverflow.com/questions/5418700/couchdb-read-write-restrictions-on-users-database