Search code examples
couchbasecouchbase-lite

How to create cblite2 file with python script


I was trying to use couchbase in one of my android applications. This app will have static data that are scraped from the web. So I want to generate a cblite2 file with my python script and insert those data and then use this cblite2 file in android. I can load data from an existing file according to this. But how can I generate my initial cblite2 file?


Solution

  • You could use the cblite command line tool to create the database. There are a couple of ways to do the import. I'll describe what seems to me like the simplest way.

    Have your script save the JSON documents to a directory. For this example, let's call the diretory json-documents. Use the desired document ID as the base name, and .json as the extension. For example, if you want a document's ID to be "foo", the filename would be foo.json.

    Then use the cblite cp command to import the documents into a new database:

    cblite cp json-documents/ myNewDatabase.cblite2
    

    You can use the other cblite subcommands to verify the import was successful.

    List the document IDs:

    cblite ls myNewDatabase.cblite2
    

    Display the contents of a document:

    cblite cat myNewDatabase.cblite2 someDocumentId