我正在使用来自沙发和邮袋db的过滤复制,最初我在客户端创建一个数据库,它将复制回couchdb。当我添加文档未与couchdb同步的设计文档时。
我正在使用pouchdb版本6.1.0
请找到下面的代码段
<script type="text/javascript">
$(document).ready(function(){
$("#startbtn").click(function(){
var dbName = 'my_database';
var db = new PouchDB(dbName);
var filterDoc = {
"_id": "_design/doc_filters",
"filters": {
"by_type": function(doc, req) {
return doc._id === '_design/doc_filters' || doc.type === req.query.type;
}.toString()
}
};
db.put(filterDoc).then(function (doc) {
startSync(db,dbName);
}).catch(function (err) {
startSync(db,dbName);
});
});
function startSync(db,dbName){
var opts = {
live: false,
filter: 'doc_filters/by_type',
query_params: { "type": "xyz" },
ajax: {
timeout: 900000
}
};
db.sync('http://localhost:5984/'+dbName, opts, function (e) {
console.log(e);
});
}
});
</script>