One way sync from mobile to server

Hi,

I have been working on one particular solution where mobile will sync a document(one way) and here at sync gateway level, this document will be deleted(marking _deleted property true) after some processing thorough changes feed.

I don’t want mobile to worry about that what happened to document at server, (when I delete it increases rev )

In order to prevent this I am using

If(!doc.deleted)
{
// do nothing
}

However it is still creating conflicts at mobile side.

second I also tried import filter to prevent this. no luck.

Am i missing something on my understanding? Or is there any other way to do that?

Any help is greatly appreciated.

Which way is your replication? (Mobile to SGW (push) or SHW to mobile (pull))

Not entirely sure of the sequence of events here. Did you remove a document directly on server and is it the case that you don’t want that to be synced to the mobile app?

Thanks Priya for reaching out. We have both types of replications i.e. few types of document one way -> mobile to SGW(push) and few types of documents SGW to mobile (pull).

None of them are bi-directional.

Question that i had before was -> For only One way -> mobile to SGW(push) I wanted to prevent this to reflect back at mobile. Since this would be one way push, Mobile should not be worried about if document is updated at server side. right?

However, Every time i make update at server side(In this case, I am marking as deleted), Mobile is failing to push new document, because of conflicts.

in order to prevent this behavior,I need help to modify sync function or some settings which could help mobile to keep pushing new documents without conflicts and without worrying about server side.(I don’t want to sync back to mobile for this few document type)

@priya.rajagopal - Just reminder! I am waiting for your response.

Which version of Sync Gateway are you using ? If you are on Sync Gateway 2.0 and you don’t want some documents on server to be synced over to the mobile clients then you can use the import-filter filter out documents you don’t want synced

Example:

"import_filter": `
        function(doc) {
           if (doc._deleted == true ) {
	      return true;
        }
       // docs of type foo are not synced 
           if (doc.type == "foo" ) {
             return false;
           } 
         
          return true;
        }
        `

Hi @abhi.chouksey,

This looks like a bad design when we want to push the document to server and then update it on server but dont want that document back to client and then push again. Naturally this is conflicting situation.

I will recommend to create a new document id for this document which one can understand on the server side.n for example lets say type of the document is type1, device is d1 and time stamp is t1 then I will create a document id as type1::d1::t1 and then have these fields in the json also having a channel if required.

Then when I will push this document it will always be a new document. Now even if an update is done on server I am not listening to that update and this will not come down. Second time I will again want to push the document but the timestamp will be different. So here you are its a new document.

The problem with this approach is that it can increase the number of documents on the server side. For that when the processing on the server side is done by a background process it can purge the document using admin API.

In local you will need to write a purge mechanism also. I can suggest using ttl on local and expiry on sync gateway but then it should be based on the business logic. Like one will want to purge from local only when the document is synced to server. And purge from server only when the processing is done.

I hope this will help you creating a better design.

Thanks @pankaj.sharma for good insight and validating without knowing(great mind thinks alike) ! I am doing exactly what you have described.

@abhi.chouksey So does it mean its resolved ?

I guess it is now! Thanks for your input, I marked your comment as solution.