You can create a CouchDB view that lists users. Here are a few resources on CouchDB presentations that you should read to get a more detailed picture on this topic:
So, let's say you have these documents:
{ "_id": generated by CouchDB, "_rev": generated by CouchDB, "type": "user", "name": "Johny Bravo", "isHyperlink": true }
Then you can create a CouchDB view (part of the map) that looks like this:
// view map function definition function(doc) { // first check if the doc has type and isHyperlink fields if(doc.type && doc.isHyperlink) { // now check if the type is user and isHyperlink is true (this can also inclided in the statement above) if((doc.type === "user") && (doc.isHyperlink === true)) { // if the above statements are correct then emit name as it key and document as value (you can change what is emitted to whatever you want, this is just for example) emit(doc.name, doc); } } }
When the view is created, you can request it from the node.js application:
// query a view db.view('location of your view', function (err, res) { // loop through each row returned by the view res.forEach(function (row) { // print out to console it name and isHyperlink flag console.log(row.name + " - " + row.isHyperlink); }); });
This is just an example. First, I would recommend exploring the above resources and exploring the basics of CouchDB views and its capabilities.
source share