I am trying to figure out how the filter works.
My goal is to exclude documents with a type
of user_submits and only grab the documents with type
form that was created less than a month ago.
Am I doing this right? Do I just return doc
if all my needs are met?
local_db.replicate.from(remote_db, {
filter: function (doc) {
if(doc.type == 'form')
if(doc.created >= (Math.floor(Date.now() / 1000)-2419200))
return doc;
else if(doc.type !== 'user_submits') return doc;
}
}).on('complete', function () {
console.log("success");
})
.on('error', function (err) {
console.log("error");
});
I only ask this because the only example I see for filtering is something like the following and I'm confused on the logic behind it.
filter: function (doc) {
return doc.type === 'marsupial';
}
A filter function return true of false. It returns true if the document should be replicated. Otherwise false.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.