Skip to content

Instantly share code, notes, and snippets.

@redtrumpet
Last active August 29, 2015 14:02
Show Gist options
  • Save redtrumpet/2028f77756e17219a234 to your computer and use it in GitHub Desktop.
Save redtrumpet/2028f77756e17219a234 to your computer and use it in GitHub Desktop.
pouchdb error
<!doctype html>
<html>
<body>
<script src="https://github.com/daleharvey/pouchdb/releases/download/2.2.3/pouchdb-2.2.3.js"></script>
<script>
var ddocs = [{
_id: '_design/spiele',
views: {
spiele: {
map: function (doc) {
emit(doc);
}.toString(),
reduce: '_count',
}
}
}, {
_id: '_design/spieleByAutor',
views: {
spieleByAutor: {
map: function (doc) {
if (doc.autoren && doc.autoren.length > 0) {
for (var i = 0; i < doc.autoren.length; i += 1) {
emit(doc.autoren[i]);
}
}
}.toString(),
reduce: '_count',
}
}
}, {
_id: '_design/kategorien',
views: {
kategorien: {
map: function (doc) {
if (doc.kategorien !== undefined && doc.kategorien !== null) {
for (var i = 0; i < doc.kategorien.length; i += 1) {
emit(doc.kategorien[i]);
}
}
}.toString(),
reduce: '_count',
}
}
}];
var db = new PouchDB('spiele_dev');
for (i = 0; i < ddocs.length; i += 1) {
db.get(ddocs[i]._id).then(function (info) {
console.log(info);
}).catch(function (err) {
if (err.status === 404) {
db.put(ddocs[i]).then(function (info) {
console.log(info);
}).catch(function (err) {
console.error(err);
});
}
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment