1

Is it possible in Couchbase to get notified only if a specific key in a document was changed (in the SyncGateway) or could that be achieved through LiveQueries and how?

{
 "test": "BaseCouch"
 "test2": "foo"   
}

changing to:

{
 "test": "CouchBase"
 "test2": "foo"   
}

And than getting notified that only

Event : in DOC the KEY changed FROM X to Y

pbertsch
  • 320
  • 2
  • 14

1 Answers1

0

There are a few ways you could do this.

You could set up a sync function in Sync Gateway that assigns the document to a special channel whenever the value for that key changes. You'd then do something like run a filtered replication that listens to that channel, and use a change listener to notify your app.

You can also do this with a live query. The most explicit way would be to create a View with a map function that emits that key/value as its index. Then just set up a live query to get notified of changes on the view.

You could also set up a general database change listener and check for the value to change directly yourself.

I can think of other ways to do it, but those seem like the most sensible. The efficiency, and which you pick is going to depend on specifics of your application.

Hod
  • 2,236
  • 1
  • 14
  • 22
  • thanks for the answer. I thought about the SyncGateway example but it seems a lot of work for little gain. Right now I use a PullReplicator which is working fine but a lot of times I only change one or two keys in my Document but because the PullReplicator does not know it, it gets synced completely. What would you recommend doing with the PullReplicator (Continuous). Stopping it and making it One-Shot while I use the LiveQuery ? – pbertsch May 11 '17 at 19:59
  • Not sure if I'm understanding your question, LiveQuery responds to changes in the local database. So you'd normally want the pull replication to keep running (since that's getting the changes from SG). It's on the roadmap to have more efficient handling of this scenario, but no confirmed dates. – Hod May 11 '17 at 21:22
  • Thanks a lot @Hod , appreciate your input on the matter. – pbertsch May 15 '17 at 17:59