偶尔我会得到以下内容:
http://myhosted.couchdb.com:5984/userdb-6938/_local/H73d9PBjwCczSUMy4NZ6bA%3D%3D 409(冲突)
标题回复是:{"error":"conflict","reason":"Document update conflict."}
请求有效负载是:
{
"_id": "_local/f.kaEuoL4i41KgUTkCHAyg==",
"_rev": "0-10",
"session_id": "735AF8E9-BF62-191F-9A63-760C922E1259",
"history": [{
"last_seq": 77,
"session_id": "735AF8E9-BF62-191F-9A63-760C922E1259"
},
{
"last_seq": 67,
"session_id": "908B46C9-06C4-A60D-9189-CCE33ECEB252"
},
{
"last_seq": 59,
"session_id": "7B7A1737-D6AB-23F2-B3C3-954DFAC3F91A"
},
{
"last_seq": 52,
"session_id": "A7B639E5-CCEF-E1DE-91B2-8E27AB4AFB5B"
},
{
"last_seq": 45,
"session_id": "D8A322C2-5421-D493-91FB-DD85258D2194"
}],
"replicator": "pouchdb",
"version": 1,
"last_seq": 77
}
使用pouchDb执行某些操作时会发生这种情况,即此代码有时会触发它:
try {
await db.bulkDocs(toBeSaved)
} catch (err) {
errorCallback(err, importObj)
}
我理解local docs是无法复制的文档但我是否需要担心显示的错误消息? docs确实解释了处理冲突,但这似乎是我无法做任何事情的。另外,由于这是一个批量操作,哪个文件正是导致冲突?
编辑
我的getLocalDb调用(将连接分类到小袋/沙发):
getLocalDb: function (onSyncCompleteDispatch) {
var localDb = new PouchDb(this.databaseName, {auto_compaction: true})
var liveDb = this.getLiveDb()
var self = this
// Only send a db object once it has sync'd with the remote host.
return new Promise(function (resolve, reject) {
resolve(localDb)
// We're not using continuous sync because the loading bars on the app will go wild
// We don't need to get data without users clicking anything at this point.
localDb.sync(liveDb, {
live: false,
retry: false
}).on('complete', function (info) {
var requiresReload = info.pull.docs_written > 0 || info.pull.docs_read > 0 || info.push.docs_written > 0 || info.push.docs_read > 0
if (requiresReload) {
typeof self.onSyncCompleteCallback === 'function' && self.onSyncCompleteCallback(info)
}
}).on('error', function (err) {
if (err.message === 'getCheckpoint rejected with ') {
// Don't need to resolve anything here as we resolved it above and nothing will have
// changed as no connection is available.
console.log('No live connection available, return local (without sync).')
} else {
typeof self.onSyncErrorCallback === 'function' && self.onSyncErrorCallback(err)
reject(err)
}
})
})
}