Couchbase mobile replication through REST-API

426 views Asked by At

While trying to integrate couchbase mobile (version 1.1.0) in our hybrid mobile app (ionic), we ran into an issue with the push replication on iOS.

At some point in the application (after the local database has been created and so on) a design document with some views is created successfully. A continuous push and pull replication is created and started as well.

When polling for the push replication status we noticed that it had stopped (not normal for a continous replication) shortly after it had been started.

Couchbase mobile replied with an error (404)

WARNING: CBL_Pusher[http://server:4985/bucket-sync-gateway]: _bulk_docs got an error: {
   error = "bad_request";
   id = "_design/app";
   reason = "Invalid doc ID";
   status = 400;
}

The sync gateway logged a similar error:

BulkDocs: Doc "_design/app" --> 400 Invalid doc ID (400 Invalid doc ID)

This only happens on iOS. The android version doesn't have issues with the replications (maybe the design documents are ignored?)

  • Why does the replication try to sync design documents on ios and not on android?
  • Should design documents be synched?
  • Is there a way to prevent certain document of being synched? (Native api's provide a filtering mechanism on replications, but the rest-api does not)

Any idea what could be the problem here?

Cheers,

Bert

1

There are 1 answers

8
Jens Alfke On BEST ANSWER

Which versions of Couchbase Lite and Sync Gateway are you using? I believe the behavior has improved in version 1.1 of each. Specifically, Sync Gateway now returns 403 Forbidden instead of 400 Bad Request when a client attempts to upload a design document. The Couchbase Lite replicator will keep going after this status instead of stopping with an error.

Design documents are problematic since they usually contain executable (JavaScript) code in the form of map, reduce or filter functions. For security reasons Sync Gateway (like CouchDB) won't allow a non-admin client to upload one.

Worse, it is probably a violation of your Apple developer agreement to have your iOS app download a design doc, since apps aren't allowed to execute downloaded code. (The reason I say "probably" is because the exception is JavaScript code running in a web browser. The design doc does contain JS, and your PhoneGap app code does run in a browser, but the map/reduce/filter functions run not in the browser but in a separate JS context invoked by Couchbase Lite. I am not a lawyer and I have no idea what Apple would think of that. To my knowledge it's never come up.)

—Jens Alfke (Mobile Architect, Couchbase)