0
votes

I'm fairly new to the world of CouchDB and just learned about the neat world of views. I did a bit of reading, but I'm not certain on how it works yet. My question is how could I query all the documents in a database for a matched value? I want to search a bunch of documents containing an object called username and only return the IDs of the documents that contain that...

How could I do this?

1

1 Answers

2
votes

Should be a straight-forward map function, unless I'm misunderstanding or missing something.

function (doc) {
    if (doc.username) {
        emit(doc.username);
    }
}

The document _id will be a part of your view results already, so you can just emit the username by itself. If you add include_docs=true to your querystring, you can get the entire document as well.