I use PouchDB to save user data from a website to CouchDB (on IrisCouch). Following a mistake, I pushed documents with already taken names. I tried to recover the conflicting files admitting that there was a conflict.
db.get('threshold0_1_3', {conflicts: true}).then(function (doc) {
console.log(doc, doc._conflicts);
}).catch(function (err) {
console.log(err)
});
But the doc._conflicts
is null and the document don't have a "_conflicts" property.
So I tried to create a conflict with this code:
var db = new PouchDB("http://127.0.0.1:5984/test");
var data = {"_id": "testDoc", "count": 1};
db.put(data).then(function (response) {
// handle response
}).catch(function (err) {
console.log(err);
});
// modify document
data = {"_id": "testDoc", "count": 2};
db.put(data).then(function (response) {
// handle response
}).catch(function (err) {
console.log(err);
});
// Output
o {status: 409, name: "conflict", message: "Document update conflict", error: true, reason: "Document update conflict."}
// Check if the doc contains ._conflicts
db.get('testDoc', {conflicts: true}).then(function (doc) {
console.log(doc);
console.log(doc._conflicts);
}).catch(function (err) {
console.log(err)
});
// Output:
Object {_id: "testDoc", _rev: "1-74620ecf527d29daaab9c2b465fbce66", count: 1}
undefined
What I am missing here?
A 409 indicates that the
put()
was rejected because it would have created a conflict. To manually create conflicts (if you really want to), you would need toput()
the same document twice in two different databases, and then replicate them. Here's an example script.This prints out: