N1QL Deleted Records reappearing again in couchbase server

Hello,

We are using couchbase database along with syncgateway.
Whenever I am deleting records via N1QL in couchbase server they get deleted. But after few days they get added back to the couchbase database again via syncgateway.

I have changed the metadata of purge interval to 15 days. But issue still exists.

What I have observed is the tombstones which they get created whenever I deleted records also get deleted in next 1 hour.
Am I missing any configuration here ? If anyone has faced this issue please let me know.

Thanks,
Dileep

@dileep_kumar … The Delete might be coming back(synced) from CBL after you remove(purge) it from SG/CB side. In your sync Function you can do something like this to prevent deleted docs from sync back.

{
"_id":"invoice::1234565",
"_rev":"2-2222",
"_deleted":true
}


function(doc,oldDoc){

var a = doc._id.split("::")

if(doc._deleted && doc._deleted === True){
     
       if(a[0]=="invoice"){
           requireRole(["admin","manager"])
        }else{
          requireRole("admin")
      }

       }else{
              channel(doc.channels)
   }
}