1

I use PHP SDK to get documents from a design view, and delete them.

$myCluster = new CouchbaseCluster('couchbase://127.0.0.1');
$myBucket = $myCluster->openBucket($bucketName);
$query = CouchbaseViewQuery::from('dev_view', 'old_docs');
$res = $myBucket->query($query);
foreach ($res['rows'] as $doc) 
    $res = $myBucket->remove($doc['key']);

All the docs from the view are deleted from Couchbase server, but Couchbase doesn't notify Sync Gateway to delete them from devices. When I start the App on any device (Android tablets) the documents start to sync back to Couchbase server instead of being deleted from the device. But when I delete a document from device, Sync Gateway notifies the CB server and document is deleted from CB server too.

Is there any bug with PHP SDK? Should I call a function to notify Sync Gateway after deleting documents?

Hadi Sharghi
  • 903
  • 16
  • 33

2 Answers2

1

There are two possible ways you could be using Couchbase here.

One would be if you're talking to the bucket behind Sync Gateway directly. If you are doing that, it's not an intended way to use Couchbase and deleting documents directly there is not a supported approach.

The other possible way is if you're using the "shadow buckets" feature. If you're doing that, then this sounds like it could be an issue that needs to be filed.

As a workaround, what you may want to do is use your view to identify the 'old docs' and rather than delete them through the SDK's interface, try deleting them through the Sync Gatway REST API.

Matt Ingenthron
  • 1,894
  • 14
  • 14
  • I'm talking to the bucket directly and that's because my project should have both App and web clients. For the app client I use CB Lite and therefore talking to sync gateway . But for the web client I directly talk to the bucket. If it's not the right way then what is PHP SDK good for? – Hadi Sharghi Jan 30 '15 at 07:40
  • 1
    The majority of Couchbase deployments use SDKs that talk to buckets directly, but that's not a valid deployment if you're using Couchbase Mobile's Sync Gateway owing to some particular needs in that kind of deployment. That's something the team is looking at right now. (note: I'm from Couchbase, Inc.) – Matt Ingenthron Feb 02 '15 at 19:35
  • So you say I should never talk to CB server directly and I should always use Sync Gateway REST API instead? – Hadi Sharghi Feb 04 '15 at 14:56
  • 1
    As of this writing, when using Sync Gateway there are two supported options. One is [bucket shadowing](http://developer.couchbase.com/mobile/develop/guides/sync-gateway/wcbs/bucket-shadowing/index.html) and the other is to use the [Sync Gateway REST API](http://developer.couchbase.com/mobile/develop/references/couchbase-lite/rest-api/index.html). Reading and writing directly to the bucket managed by Sync Gateway is not currently an option. There are enhancements planned for the future here. – Matt Ingenthron Feb 05 '15 at 16:46
0

Create a view on shadow bucket and delete documents from shadow bucket. Deletions on shadow bucket would get replicated to sync bucket with added metadata (e.g. _deleted = true) necessary for syncing/replication. Now any deletions made at shadow bucket would be notified/replicated to mobile devices.

user2787531
  • 41
  • 1
  • 5