Reputation: 2835
PouchDB cannot update the CouchDB entries. It gives back "Document update conflict."
I read the conflict problem on pouchdb documnetation, I tried a lot of scenario, but always the same result.
409 Document update conflict
So here the last one code:
docs.forEach((element, index) => {
if (categoriesData[element._id] != null){
pouchdatabase.get(element._id).then(function (origDoc) {
// var doc = element;
// doc._rev = origDoc._rev;
// doc.name = categoriesData[element._id].newName;
// var doc = {
// _id: element._id,
// _rev: origDoc._rev,
// name: categoriesData[element._id].newName
// };
pouchdatabase.put( {
_id: element._id,
_rev: origDoc._rev,
name: categoriesData[element._id].newName
}).then(function (response) {
console.log('updated');
}).catch(function (err) {
console.log(err);
});
});
}
});
I tried with this solution (found on Pouchdb github), but the same error...
var retryUntilWritten = function (doc) {
return pouchdatabase.get(doc._id).then(function (origDoc) {
doc._rev = origDoc._rev;
return pouchdatabase.put(doc);
}).catch(function (err) {
if (err.status === 409) {
return retryUntilWritten(doc);
} else { // new doc
return pouchdatabase.put(doc);
}
});
};
Do you have any idea how can I update the name
of the category?
Locally the name attribute will be replaced! (in pouchdb, but not will updated to the couchdb!)
Upvotes: 2
Views: 3235
Reputation: 942
Conflicting happen when you try to update a document without _rev or the revision of your documents outdated (deleted from revision tree).
So, to update without a valid _rev. You can set options force
equal true
const respond = await db.put(doc, {force: true})
read more about conflict here:
Note: to limited conflicting, limited change your document by small pieces
Upvotes: 5