Skip to content

Instantly share code, notes, and snippets.

@JeffML
Created January 14, 2017 21:10
Show Gist options
  • Save JeffML/3bd21b3f1fba0bc37228fb93d22333a2 to your computer and use it in GitHub Desktop.
Save JeffML/3bd21b3f1fba0bc37228fb93d22333a2 to your computer and use it in GitHub Desktop.
const PouchDB = require('pouchdb');
const db = new PouchDB('choices');
// doc that defines the view
var ddoc = {
_id: '_design/choice',
views: {
by_key: {
map: function (doc) {
emit(doc.key, doc.taste);
}.toString()
}
}
};
// remove any existing view, then add new one:
db.get(ddoc._id)
.then(doc => {
return db.remove(doc);
})
.then(() => {
db.put(ddoc)
.catch(function (err) {
console.error(err);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment