Nanodb 复制过滤器
Nanodb replication filter
I have a db called: 'sample'
I have _design doc that look like:
{ "_id": "_design/orgFilter",
"_rev":"9-7cd70d5ca52ddd42a3ff953c01d7cd36",
"views": {
"newView": {
"map": "function(doc) {
if(doc.type && doc.type==='organization' ){
emit(doc._id, doc.name);
}
}"
}
},
"language": "javascript"
}
And sample data like:
{ "_id": "eb425729d084d49c8cddd45c6e00b07f", "_rev":
"2-9035a8eb3fa0fef44b0927bbe7090bbd", "type": "organization",
"name": "org1" }
{ "_id": "eb425729d084d49c8cddd45c6e00b2a7", "_rev":
"3-cf39cb747db01a4a71e58c2211de7c04", "type": "organization",
"name": "org2" }
{ "_id": "eb425729d084d49c8cddd45c6e00bf37", "_rev":
"3-d263492888a5755e91788901e59756ad", "type": "organization",
"name": "org3" }
In my node server i using nano db and try use his replication function
with filter , it's look like:
nano.db.replicate('sample','http://localhost:5984/'+'b_rep',
{create_target: true,continuous:true,filter:"orgFilter/newView"} , function (err, body) {
if (!err)
console.log(body);
});
The response of this opriation is : "missing json key: newView"
What should i need to do to make this filter replication?
Thanks
您不能将视图用作过滤器。
这是一个过滤器示例:
{
"_id": "_design/orgFilter",
"_rev": "6-6574469635168a0ae817df513ac4311d",
"language": "javascript",
"filters": {
"organization": "function(doc,req){return doc.type && doc.type==='organization';}"
}
}
请注意,您需要一个 _design 文档,并且您需要在 属性 filters 下定义您的过滤器。
基本上,过滤函数需要 returns true 或 false。真意味着复制将发生。如需更多详细信息,请访问此 link.
I have a db called: 'sample'
I have _design doc that look like:
{ "_id": "_design/orgFilter",
"_rev":"9-7cd70d5ca52ddd42a3ff953c01d7cd36",
"views": {
"newView": {
"map": "function(doc) {
if(doc.type && doc.type==='organization' ){
emit(doc._id, doc.name);
}
}"
}
},
"language": "javascript"
}
And sample data like:
{ "_id": "eb425729d084d49c8cddd45c6e00b07f", "_rev":
"2-9035a8eb3fa0fef44b0927bbe7090bbd", "type": "organization",
"name": "org1" }
{ "_id": "eb425729d084d49c8cddd45c6e00b2a7", "_rev":
"3-cf39cb747db01a4a71e58c2211de7c04", "type": "organization",
"name": "org2" }
{ "_id": "eb425729d084d49c8cddd45c6e00bf37", "_rev":
"3-d263492888a5755e91788901e59756ad", "type": "organization",
"name": "org3" }
In my node server i using nano db and try use his replication function with filter , it's look like:
nano.db.replicate('sample','http://localhost:5984/'+'b_rep',
{create_target: true,continuous:true,filter:"orgFilter/newView"} , function (err, body) {
if (!err)
console.log(body);
});
The response of this opriation is : "missing json key: newView"
What should i need to do to make this filter replication?
Thanks
您不能将视图用作过滤器。
这是一个过滤器示例:
{
"_id": "_design/orgFilter",
"_rev": "6-6574469635168a0ae817df513ac4311d",
"language": "javascript",
"filters": {
"organization": "function(doc,req){return doc.type && doc.type==='organization';}"
}
}
请注意,您需要一个 _design 文档,并且您需要在 属性 filters 下定义您的过滤器。
基本上,过滤函数需要 returns true 或 false。真意味着复制将发生。如需更多详细信息,请访问此 link.