access session information from couchdb views

330 Views Asked by At

I'm new to couchdb/couchapp. I'm wondering if it's possible to access _session information from couchdb views. For example:

function(doc) {
  if (doc.username == session.userCtx.name) {
    emit(doc.username, doc);
  }
}; 
1

There are 1 best solutions below

1
On BEST ANSWER

Great question! The answer is no and it's important to understand why.

The policy about which users may see what data is done at the database level, not the document or view level. It sounds odd however it makes sense in the long-run.

The function that does have access to the session is filter functions. You can use those to create private databases per-user with all the documents they may read.

I wrote more answers about read permissions in a question about _all_docs, and also about CouchDB read permissions.