Is it possible to put
or bulkDocs
into couchdb/pouchdb and get the same behaviour as in replication, i.e. winning revision with _conflicts
instead of a 409
response?
Basically I would like to avoid the conflict
case in the following code:
const docs = Object
.keys(pendingSet)
.map(id => toDoc(deepClone(pendingSet[id]), { id, rev: this.revCache.get(id) }))
const results = await this.db.bulkDocs(docs)
const conflicts = []
for (let n = 0; n < results.length; ++n) {
const result = results[n]
if (result.error === 'conflict') {
// TODO: This needs review...
const doc = await this.db.get(docs[n]._id)
const rev = `${doc._rev.split('-')[0]}-${this.serverName}`
conflicts.push({
...docs[n],
_rev: rev
})
this.revCache.set(doc._id, rev)
} else if (result.error) {
callback(result.error)
} else {
this.revCache.set(result.id, result.rev)
}
}
await this.db.bulkDocs(conflicts, { new_edits: false })
I've gotten a bit of a hint from pouchdb but I'm still unsure how to apply it.
EDIT1: Updated with latest code.