Skip to content

Instantly share code, notes, and snippets.

@pionize
Created April 17, 2017 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pionize/f9fdf75ff0b42fd4aa26db8c031c55b2 to your computer and use it in GitHub Desktop.
Save pionize/f9fdf75ff0b42fd4aa26db8c031c55b2 to your computer and use it in GitHub Desktop.
Rookie Mistake 1: Promise Pyramid
db.allDocs({
include_docs: true,
attachments: true
}).then(function (result) {
var docs = result.rows;
docs.forEach(function(element) {
localdb.put(element.doc).then(function(response) {
alert("Pulled doc with id " + element.doc._id + " and added to local db.");
}).catch(function (err) {
if (err.name == 'conflict') {
localdb.get(element.doc._id).then(function (resp) {
localdb.remove(resp._id, resp._rev).then(function (resp) {
// etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment