Select users in couchdb

I have an HTML form for user authentication, with SQL language it is easier to extract data

select name, password from users where name='nameField' and password='passwordField'

In couchdb, I cannot use local views only temporary views:

curl -X POST -H 'Content-Type: application / json' -d '{"map": "function (doc) {if (doc.name ===" nameField "&& doc.password ===" passwordField " ) {emit (doc.name, doc.passWord)}} "} 'http: // localhost: 5984 / somedb / _temp_view

But this is not recommended ( Click here ), what should I do ?: (

thank

+3
source share
1 answer

So I usually like to do this ...

  • . , /_design/users/_views/byUserPass

  • ( ):

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

  • : http://localhost:5984/somedb/_design/users/_views/byUserPass?key=["exampleUsername", "examplePassword"]

  • , . . (, ) (, " " ) CouchDB .

, null: emit([doc.username, doc.password], null); - , .

.

+7

Source: https://habr.com/ru/post/1744066/


All Articles