How to export a couchbase bucket to a zip file that could be imported and used as initial data on an android application

I want to export a couchbase bucket to a zip file and import it into couchbase-lite when the app is first opened. I see that there are zip files available for some samples in the example projects. Trying to understand how a couchbase bucket could be exported.

couchbase server and coucbhase-lite have their own way of storing data internally. I don’t think export/import will work. If you want your android app to load data from couchbase server bucket at initialization, I would like to suggest the following steps:

  1. couchbase server is up, bucket is created, data is available in bucket
  2. install sync gateway, and configure the sync gateway db to point to couchbase server url and the bucket name
  3. set your android app to point to sync gateway service
  4. at your android initialization, start pull replication, wait until the pull replication complete
  5. now data from the bucket is available to couchbase-lite android client.

I understand the steps to sync data after the app is opened. Sometimes the size of the bucket can get big and initial time for syncing will be huge which is a very poor user experience. I remember reading couchbase blogspots that talk about packaging an initial data in the app and letting your data sync protocol sync only changes that were made after that intial data was packaged.

One example from couchbaselabs is here : . If you see, the initial data is packaged into the application. We want to do something like that. I want to know how that containing universities.cblite2 file was created.

Also, I was thinking export & import solution could work for the exact same reason that cb-server and cb-lite have their own way of storing. Regardless of how each of them store data internally, when I export documents from cb-server as individual documents, package the documents into zip format or something and import them onto a cb-lite when the app is first opened, cb-lite would store the documents in ways that it can understand. What I am not sure is, how the document revision information needed for data synchronization would be handled.

@PShri: we just zip an actual database. No need to export or extract anything. When the app initializes itself it should:

  • unzip the zipped database (packaged as an asset) into some directory D on the file system. D will then have a subdirectory called [some-name].cblite2
  • create a DatabaseConfiguration C and set its directory to D: C.setDirectory(D)
  • open the database using the above created configuration and the name [some-name]: new Database([some-name], C)

@blake.meike : I wanted to know how that actual database is produced. I have already got the answer in a different thread.

Awesome! I’m glad you have an answer!

Just a suggestion, though: “knowing how the actual database is produced” is probably not a very useful thing, for client code. Importing a database is likely to be more efficient both in terms of space and time

…lol!!! :slightly_smiling_face:

thanks so much for the information very helpful.