Pull request to create database on IOS device (of existing couchbase bucket)


#1

Hi,

I created a simple app to clone an existing database / data bucket from a couchbase to an ios device based on http://developer.couchbase.com/mobile/develop/guides/couchbase-lite/native-api/database/index.html

The app creates an empty database and then tries to pull the database from the server. It works with the “grocery-sync” bucket but not with a different database with some documents inside.

void) replicationChanged: (NSNotification*)n is only called a few times and should be called (way) more often. There seem to be no changes in the bucket (pull.changesCount is 0).

Hm, the problem seems to be that the documents are not assigned to a channel (I created the testbucket from a java app directly without sync server)?

curl http://localhost:4985/test/_all_docs?channels=true
{“rows”:[
],

And the sync function uses ‘channel(doc.channels)’ for database “test”.

Is this the problem? Then how do I assign (existing) documents of a bucket to a channel? I assume this can be done in a view? Or can I assign a channel (property) then the documents are introduced into couchbase (via Java Couchbase Client 2.02 API)?

Greetings,

Ralf

#2

I created the testbucket from a java app directly without sync server

Don’t do that! The gateway’s bucket is private and should only be modified by Sync Gateway itself. If you want to write to it from your own code, either talk to the gateway’s REST API, or use the bucket shadowing feature to create a separate bucket that you can use Couchbase SDKs to write to.


#3

Ok, thanks. I’ll try it.


#4

Hola,

I can delete a bucket via sync gateway.

curl -X DELETE http://Administrator:@127.0.0.1:4985/test/

but how can I create a new database?

curl -X PUT http://Administrator:@127.0.0.1:4985/test/
{“error”:“Bad Request”,“reason”:“Bad JSON”} is not complete?

According to http://docs.couchbase.com/sync-gateway/

“The body of the request contains the database configuration as a JSON object ()the same as an entry in the databases property of a configuration file. Note that this doesn’t create a Couchbase Server bucket—you need to do that before configuring the database.”

So, first I need to create the bucket in the couchbase, then configure it via the sync gateway? Can you/someone tell me how?

Greetings,

Ralf


#5

Create the bucket in the Couchbase Server web admin UI; it’s easy.

You’ll probably want to add the database to Sync Gateway by editing its config file. If you do it using a PUT request, the setting isn’t persistent and will need to be redone next time you start the gateway.


#6

I created the bucket manually. Then I start the sync gateway pointing to the bucket. I thought it is required to configure something more to be able to sync.

Then I try to add a test document via

curl -X PUT -u Administrator: -H “Content-Type: application/json” http://127.0.0.1:4985/testdb/testdoc?new_edits=false -d ‘{“testkey”:“testvalue”}’
(according to http://docs.couchbase.com/sync-gateway/#sync-rest-api)

and get the response …
{“error”:“Bad Request”,“reason”:“Bad _revisions”}

I asssume(d) that I don’t need a revision for an initial document? Nevertheless if I add a “rev” it’s the same error.


#7

Don’t use new_edits=false. That mode is pretty much only used by the replicator; it requires that the document be an existing revision complete with some extra metadata such as a revision history.


#8

Thanks (for the help!), I was able to create the bucket. I am not a web developer … maybe this would have helped … it’s often the little things in webdev.


#9

Yeah, we don’t have much tutorial documentation of the REST API. That’s partly because it’s nearly identical to the CouchDB REST API, which is already documented pretty well elsewhere. (That isn’t an excuse, and we do plan to add more docs, but at least for this particular doc hole we can point people to external sites like the CouchDB docs and the CouchDB book.)