Keep data in document when sync gate way

Hi,
I have a problem, I want to keep data inside document when sync gate way.
Ex: document in Mobile Song(“name”:“Sorry”,“id”:“123”,“singer”:“justin bieber”)
Document in Couchbase Server Song(“name”:“Sorry”,“id”:“123”,“singer”:“justin bieber”,“clickNumber”:“100”)
When I update document in Couchbase Server, I do not allow it to update the “clickNumber” field of a document in client user.
Because “clickNumber” is field in local user
Does anyone have a solution to this problem

You cannot do partial syncs of a document to mobile clients. Read access is enforced on a document level granularity. So if there are fields in document that you want hidden from the mobile clients, then you will have to model your documents so the hidden fields (clickNumber in your example) is in a separate document .

Thank you very much. But I’m sorry, I had a wrong question. I mean:

  • Document in Couchbase Server: Song(“name”:“Sorry”,“id”:“123”,“singer”:“justin bieber”)
  • Document in Mobile: Song(“name”:“Sorry”,“id”:“123”,“singer”:“justin bieber”,“clickNumber”:“100”)
    Whenever I want to update Song’s document via “Sync gate way”, filed “clickNumber” in client mobile still exists and has a value of 100. Because the “click” field is only available on client mobile.
    Thank you!

Not sure I understood your question. Do you want to have a document with fields local only to mobile ? If so, create a separate document to track clickNumber and filter those documents from getting replicated to the server

Previously, I designed my documents:

  • Mobile: Song(“name”:“Sorry”,“id”:“123”,“singer”:“justin bieber”,…)
    SongDataUser(“id”:“123”,“clickNumber”=100,…)
  • Server : Song(“name”:“Sorry”,“id”:“123”,“singer”:“justin bieber”,…)
    I have done “leftJoin” to take all the song of singer “justin bieber”, but “leftJoin” combined with “orderBy” reduces performance ( only “leftJoin” takes 50ms, but “leftJoin” combined with “orderBy” takes ~ 1000->1200 ms, total 120k documents). So I don’t want to user “leftJoin” combined with “orderBy”
    I have combined two Song and SongDataUser document in to Song(“name”:“Sorry”,“id”:“123”,“singer”:“justin bieber”,“clickNumber”=100…).
    And I want to keep vale of filed “clickNumber” whenever Sync gate way working.
    Have you understood my question yet?
    Thank you!

Yes, Looks like I had understood your question correctly . So what I responded with earlier holds.

You cannot selectively push up(or pull down) parts of your document. You will have to model your data the way you had done previously.

If performance is an issue, indexing should help. Can’t speak to why orderBy is adding the overhead. But, please raise that as a separate post as that’s not related to the original subject about sync. Include specifics of CBL platform, version, query.explain output etc

Thanks for your answers very much! :slight_smile: