I am using Couchbase server with Sync_gateway.
When I delete records from couchbase bucket using N1QL ‘delete’ query and the deleted records exists on mobile devices, then the deleted records gets added again to the couchbase bucket.
If I want to avoid it how can I achieve it.
I have also tried following in the mobile application,
Created a flag (With default value 0) for every documents I am uploading from mobile device.
While syncing the document we update the flag to 1.
I have set a filter to push replication, this filter restricts the documents for whome the value is 0.
With this logic any document needs to be uploaded to the cocuhbase bucket only once.
This approach works as long as the mobile application is running, if I restart the mobile application, all the synced documents existing on mobile device, and deleted from couchbase bucket, gets uploaded to the couchbase server.
When the app is restarted then is there any chance that the records are getting added to couchbase bucket (from mobile device) without push replication getting called ?
Is there any event from mobile side that I can handle in order not to allow these deleted records to the cocuhbase bucket again.
What version of the platform are you using ?
If you are not leveraging shared bucket access capability, then deletions made directly on the server will not be synced over to the mobile clients unless you are using bucket shadowing or unless you made those deletes via the SGW REST API. So since the mobile clients don’t know of the deleted records they will get pushed back again on restart.
If you are using SGW 1.5 and above, please follow instructions to enable shared bucket access - that will ensure that even deletes via N1QL will be synced to mobile clients.
You should not have to do that . The replication protocol does all the hard work for you, tracks what has been synced and not.
If I am using flush bucket, then also I can see the above problem i.e. the documents deleted from CB bucket and existing on mobile devices are coming to the CB bucket after SG restart.
I do not want these documents again coming to CB bucket.
What needs to be done for that.
observed in - CB 1.4.6, SG 1.4.1.
Also observed one thing, when I restart the sync_gateway then only these records are coming back to CB bucket.
Is there any relation between the two (I mean whenever SG gets restarted get restarted, all the data existing on mobile devices will get back to CB bucket.)
As mentioned in my previous response - you have two options.
That said, I would discourage use of bucket shadowing as that is deprecated in 1.5 and above. So use the other technique of making changes via SGW API.
Yes. When you restart SGW, it will attempt to “catch up” on the syncing and so documents that are not deleted on CBL will be synced up.
Again, -Deletions made directly on CB Server will not sync unless you implement one of the approaches mentioned above. So these documents keep coming back because the deletes have not synced over to mobile clients and they have no knowledge of the deletes.
If you can’t do that, then your other option will have to purge the documents locally on each of the devices that hold it after they push up the documents . That will remove the documents from local database .
If you are on 1.x version of CBL mobile, you can also set expirationDate on documents to automatically purge.
Remember, Purges don’t get replicated.