【发布时间】:2016-09-29 02:39:44
【问题描述】:
stack:nodejs、backscore.js v1.3.3、underscore.js v1.8.3、JQuery v2.2.4、cordova v6.1.1、https://pouchdb.com/download.html v6.0.5、https://github.com/jo/backbone-pouch v?、https://github.com/apache/cordova-plugin-device
我已经使用 _id 轮询了 todos-db 的记录并更新了 _rev 属性,但我找不到摆脱这些冲突的方法,因此感谢所有帮助:
在我的 TodoModel 中,我正在做:
return Backbone.Model.extend( {
idAttribute: "_id",
db: new PouchDB( "todos-db" ),
sync: this.BackbonePouch.sync( {
db: this.db,
fetch: "query",
options: {
query: {
include_docs: true
}
}
} ),
initialize: function(){
this.listenTo( Backbone, "updateRec", function( model ){
this.updateRec( model );
} );
},
updateRec: function( revRec ){
var self = this;
console.log( "revRec:", revRec );
this.db.get( revRec._id, { conflicts: true } ).then( function( doc ){
console.log( "doc:", doc ); // doc has no conflicts
revRec._rev = doc._rev;
return self.db.put( revRec );
} ).then( function( result ){
console.log( "updateRec result:", result );
return result;
} ).catch( function( err ){
// TODO: the above 'put' is throwing multiple confict errors, yet the db is updating after 7 tries
console.log( err );
} );
}
} );
});
在日志中,revRec 给了我:
_id:"2016-09-27T16:45:34.297Z"
_rev:"5-b554a2b4989efedac3ca3ccb679aa42e"
completed:false
delegatedTo:"Jen"
due:"Friday"
priority:"A"
project:"home"
task:"MBath concept"
'put' 结果给了我:
{ok: true, id: "2016-09-27T16:45:34.297Z", rev: "6-c6647848d965c35c7ac4f968cac7a91b"}
捕获错误是:
CustomPouchError {status: 409, name: "conflict", message: "Document update conflict", error: true}
【问题讨论】:
标签: backbone.js pouchdb