hypothetical sync function question

18 views
Skip to first unread message

Jeremy Kelley

unread,
Feb 26, 2015, 3:13:52 PM2/26/15
to mobile-c...@googlegroups.com
Hi all,

I would like to create records on the device, then sync them through syncgw to couchbase.  I then have external processes that will manipulate those documents.  I then don't want them to sync back to iOS.

The processes that work on docs on the server would add a _serveronly=true member to the document.

Can I do something like this with the sync function?

      "sync":`function(doc) { if (doc._serveronly) return; ....other real sync channel logic ...}`,


I'm in the middle of setting up a simple test to see if this will even work, but I'm wondering if there's any adverse effects to this that I'm missing or if it will even work this way.

Any thoughts (especially good ones) appreciated.

-jeremy


--
The Christian ideal has not been tried and found wanting;
it has been found difficult and left untried – G. K. Chesterton

Jens Alfke

unread,
Feb 26, 2015, 4:08:13 PM2/26/15
to mobile-c...@googlegroups.com

On Feb 26, 2015, at 12:13 PM, Jeremy Kelley <jer...@33ad.org> wrote:

I would like to create records on the device, then sync them through syncgw to couchbase.  I then have external processes that will manipulate those documents.  I then don't want them to sync back to iOS.

To accomplish this, all you need to do is make sure that the sync function doesn’t add the docs to any channels that are accessible to clients. You don’t even need to modify the document on the server.

For example, say these docs are identified by a property “type”:”sendonly”. Then the sync function could do something like
if (doc.type == ‘sendonly’) {
channel(“serverprocessing”);
return;
}
So these docs only get added to one channel, “serverprocessing". Then you just ensure that clients don’t have access to that channel, and that the server-side process monitors that channel’s _changes feed.

—Jens

Jeremy Kelley

unread,
Feb 26, 2015, 9:13:19 PM2/26/15
to mobile-c...@googlegroups.com
Jens,

Will this then remove the documents from the device as part of the sync?

I think this will work if so.  Thanks for the help!

-jeremy




--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/C19F37D4-8086-464F-B889-F085388E7394%40couchbase.com.
For more options, visit https://groups.google.com/d/optout.

Jens Alfke

unread,
Feb 26, 2015, 9:39:00 PM2/26/15
to mobile-c...@googlegroups.com

On Feb 26, 2015, at 6:13 PM, Jeremy Kelley <jer...@33ad.org> wrote:

Will this then remove the documents from the device as part of the sync?

No. If you want to do that, you’ll need to use the -purge method on the client after the replication completes.

—Jens
Reply all
Reply to author
Forward
0 new messages