Couchdb using nano , how to write search query -
i facing problem using couchdb. using nano module in nodejs. how can implement search match user name , password. tried this
body.rows.foreach(function(row) { if(row.doc._id==user_id && row.doc.password==password){ found = true; data = row; } });
but slow process
your code body.rows.foreach ...
map function (it iterates on every row) executes filter function if(row.doc._id==user_id ...
row. thats couchdb views - same.
but slow process
true. because of couchdb creates index (a b-tree file inside couchdb's database directory) , keeps index up-to-date. performance advantage every request result taken prepared index instead of just-in-time calculation in example.
the couchdb view map function like:
function(doc) { emit([doc._id,doc.password], null) }
the key of every row [:username,:password]
, value null
. if request
/:db/:ddoc/_view/:name?key=[":username",":password"]
you row immediately. append &include_docs=true
, whole doc appended row (alternatively emit partial of doc value instead of null
)
handling user accounts in couchdb
user accounts , passwords confidential data. couchdb has built-in _users
db it. not go details of access control specifics of db want store user account data there!. if need account data outside db interpret docs "public profiles" e.g. let users discover , connect each other.
Comments
Post a Comment