views:

211

answers:

2
+4  A: 

This is how I usually like to do it...

  1. Create your design doc and view. Ex., /_design/users/_views/byUserPass

  2. Your map function might look something like this (no reduce function):

    function(doc)
    {
      if(doc.docType == "user")
        emit([doc.username, doc.password], doc);
    }

  3. Then I can query like this: http://localhost:5984/somedb/_design/users/_views/byUserPass?key=["exampleUsername", "examplePassword"]

  4. 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.

Sam Bisbee
It helped me a lot I am very thankful to you =)
2x2p1p
Awesome, glad to hear that! :-)
Sam Bisbee
A: 

this works fine :)

Plutarco Gonzalez