我在Android上使用CouchDB和CouchBase Lite。我想在我的設備上覆制數據庫,因爲我想使用the filtered replication。將函數代碼映射爲CouchDB上的過濾器複製器
我已經寫了和腳本,當我在Futon上運行它,並且顯示了所有帶有我編寫的requeriments的文檔。
我的問題是,如果我使用代碼作爲過濾器它不適用於我的移動設備,我沒有得到我需要的requeriments文件。
這是在蒲團效果很好(對不起滾動)功能
function(doc) {
if (doc.ismaster != true &&
(Math.ceil((new Date(Date.now()).getTime() - new Date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).getTime())/(1000 * 3600 * 24)) <=360) &&
((((doc.type=='field_order') && (Math.ceil((new Date(Date.now()).getTime() - new Date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).getTime())/(1000 * 3600 * 24)) <=10))) ||
(((doc.type=='consumption_report') && (Math.ceil((new Date(Date.now()).getTime() - new Date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).getTime())/(1000 * 3600 * 24)) <=10))) ||
(((doc.type=='production_order') && (Math.ceil((new Date(Date.now()).getTime() - new Date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).getTime())/(1000 * 3600 * 24))<=10))) ||
(((doc.type=='work_report') && (Math.ceil((new Date(Date.now()).getTime() - new Date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).getTime())/(1000 * 3600 * 24)) <=40))) ||
(((doc.type=='pallet') && (Math.ceil((new Date(Date.now()).getTime() - new Date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).getTime())/(1000 * 3600 * 24)) <=10))) ||
(((doc.type=='shipment') && (Math.ceil((new Date(Date.now()).getTime() - new Date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).getTime())/(1000 * 3600 * 24)) <=10))) ||
(((doc.type=='sowing_report') && (Math.ceil((new Date(Date.now()).getTime() - new Date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).getTime())/(1000 * 3600 * 24)) <=10))))){
emit([doc.type], doc);
}
}
這是複製過濾器不使用相同的代碼工作:
"filters": {
"666": "function(doc, req) {
if (doc.ismaster != true &&
(Math.ceil((new Date(Date.now()).getTime() - new Date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).getTime())/(1000 * 3600 * 24)) <=360) &&
((((doc.type=='field_order') && (Math.ceil((new Date(Date.now()).getTime() - new Date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).getTime())/(1000 * 3600 * 24)) <=10))) ||
(((doc.type=='consumption_report') && (Math.ceil((new Date(Date.now()).getTime() - new Date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).getTime())/(1000 * 3600 * 24)) <=10))) ||
(((doc.type=='production_order') && (Math.ceil((new Date(Date.now()).getTime() - new Date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).getTime())/(1000 * 3600 * 24))<=10))) ||
(((doc.type=='work_report') && (Math.ceil((new Date(Date.now()).getTime() - new Date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).getTime())/(1000 * 3600 * 24)) <=40))) ||
(((doc.type=='pallet') && (Math.ceil((new Date(Date.now()).getTime() - new Date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).getTime())/(1000 * 3600 * 24)) <=10))) ||
(((doc.type=='shipment') && (Math.ceil((new Date(Date.now()).getTime() - new Date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).getTime())/(1000 * 3600 * 24)) <=10))) ||
(((doc.type=='sowing_report') && (Math.ceil((new Date(Date.now()).getTime() - new Date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).getTime())/(1000 * 3600 * 24)) <=10)))))
return true;}",
我做錯了什麼?
你使用的是couchbase同步網關嗎? –
抱歉,我沒有使用CouchBase,我正在使用couchDB – JoCuTo