I am having some trouble using the nano wrapper for couchDB within NodeJS:
https://github.com/dscape/nano
My question is, how do I find and return all users whose email matches '[email protected]?'. What if I only wish to return the name field?
I am confused by the concenpt of views and designnames/viewnames and if someone could show me an example call, that would be wonderful.
Thanks,
var nano = require('nano')('http://localhost:5984');
nano.db.create('users');
var users = nano.db.use('users');
user.views()//what parameters go in here?
/*example user object
user = {
'id' : '123',
'email' : '[email protected]'
'name':'John Doe'
}
*/
Looks like you need to create the view in couchdb before accessing it with nano. Views are attached to design documents as map (and optionally) reduce functions.
See this for more info: http://wiki.apache.org/couchdb/HTTP_view_API and this: http://guide.couchdb.org/editions/1/en/views.html
Your Design document for your users database might look something like the following:
{
"_id":"_design/usersddoc",
"_rev":"12345",
"language": "javascript",
"views":
{
"byEmail": {
"map": "function(doc) { if (doc.email) emit(null, doc.name) }"
}
}
}
It's important to understand the basics of how CouchDB works before using a library, otherwise you will be all kinds of confused. CouchDB has a fairly simple RESTful JSON interface, I recommend reading the Definitive Guide and browsing the Wiki to get a good idea of how it works.