Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save carloshanson/c8eee84eb6510cfbd49db1d1da9f8dc6 to your computer and use it in GitHub Desktop.
Save carloshanson/c8eee84eb6510cfbd49db1d1da9f8dc6 to your computer and use it in GitHub Desktop.
emit document matching properties of an object
// CouchDB document
{
"_id": "e44f991ff6d04174bb932fcfcb0008aa",
"_rev": "2-f4f2de9cb942435a9213f0f2cd09d902",
"user": "user1",
"key_level1": {
"abc": {
"type": "text"
},
"bcc": {
"type": "text"
}
}
}
// View to return user and type
function(doc) {
if (doc.user) {
for each (var item in doc.key_level1) {
if (item.type === 'text') {
emit([doc.user, item.type], doc);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment