This is how I usually like to do it...
Create your design doc and view. Ex., /_design/users/_views/byUserPass
Your map function might look something like this (no reduce function):
function(doc)
{
if(doc.docType == "user")
emit([doc.username, doc.password], doc);
}Then I can query like this:
http://localhost:5984/somedb/_design/users/_views/byUserPass?key=["exampleUsername", "examplePassword"]
If I get a returned row, then the credentials were correct. As a bonus, I also get all of the user's information. Now I can update their session (ex., put their user ID into the session) or the document (ex., update "when last logged on") without having to make an additional call to CouchDB for their info.
If you don't want to update anything, then return a value of null: emit([doc.username, doc.password], null);
- this will reduce bandwidth consumption as well, as you're no longer passing the whole doc back.
Cheers.