Skip to content

Instantly share code, notes, and snippets.

@5minpause
Created January 21, 2016 16:48
Show Gist options
  • Save 5minpause/e90e65223d3cfac7ff9c to your computer and use it in GitHub Desktop.
Save 5minpause/e90e65223d3cfac7ff9c to your computer and use it in GitHub Desktop.
var ddoc = {
_id: '_design/index',
views: {
index: {
map: function mapFun(doc) {
if (doc.table_name) {
emit(doc.table_name);
}
}.toString()
}
}
}
// save the design doc
localDb.put(ddoc).catch(function (err) {
if (err.status !== 409) {
throw err;
}
// ignore if doc already exists
}).then(function () {
// find docs where table_name === 'channels'
return localDb.query('index', {
key: 'channels',
include_docs: true
});
}).then(function (result) {
// handle result
console.log(result);
}).catch(function (err) {
console.log(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment