Working with the Collections Developer Preview

    Collections is introduced as a Developer Preview feature in Couchbase Server 6.5 & 6.6, and is the default in Server 7.0. The 3.x API SDKs all work with Collections and Scopes. As a practical demonstration, we have a collections-enabled version of the Travel Sample application.

    The Developer Preview of the 7.0 Collections feature in Couchbase Server is fully implemented in the 3.x API versions of the Couchbase SDKs. When working with other server versions, the defaultcollection is used from the SDK. Here we show how to access individual collections in the Developer Preview version of Couchbase Server 6.5 & 6.6, with a collections-enabled version of our Travel Sample application. User documents and flight documents are split into user and flight collections. Something that previously had to be done with key-value references to different types or categories of data.

    Travel Sample app — with Collections

    Travel Sample Application uses the Travel Sample data Bucket, which ships with Couchbase Server. For Couchbase Server 6.5, make sure that you have at least one node each of data; query; index; and search. For a development box, mixing more than one of these on a single node (given enough memory resources) is perfectly acceptable. If you have yet to install Couchbase Server in your development environment, start here.

    Then load up the Travel Sample Bucket, using either the Web interface or the command line. You will also need to create a Search Index — Query indexes are taken care of by the Sample Bucket.

    Enabling Developer Preview should only be done on a development machine; there is no upgrade path available from a DP-enabled Couchbase Server.


    As well as the Python SDK 3.1 and Couchbase Server, set up as described above, you will need git to fetch the travel sample application code:

    git clone

    Change directory into your cloned repository, and check out the Collections branch (in the case of the Python SDK, 6.5-collections).

    git checkout 6.5-collections
    • Before building the Collections-enabled version of the Travel Sample Application, you need to enable this DP feature (see warning above).

      Enable Collections Developer Preview
      /opt/couchbase/bin/couchbase-cli enable-developer-preview --enable -c http://localhost:8091 -u Administrator -p password
      Developer preview cannot be disabled once it is enabled. If you enter developer preview mode you will not be able to upgrade. DO NOT USE IN PRODUCTION.
      Are you sure [y/n]: y

    The Travel Sample Bucket needs altering to be split into collections. There is a script to do this included with the Travel Sample App — run:

    Create Sample Collections
    sh Administrator password

    adjusting for any changes you have made to server URL, or admin password. You should now have the Travel Sample Data Bucket split into collections:


    Running the Travel Sample Application

    Next, edit the file to reflect the username, password and host that you require. You can also specify commandline arguments at runtime:

    $ python3 -c <host> -u <username> -p <password>

    After the build, with your Web browser of choice, head to port 8080 of the local machine — http://localhost:8080.

    Using the Sample App is the same as with the non-collections version that we cover in our introductory doc, but we’re assuming you’ve come here to see Collections in use in the codebase.

    Sample App Backend

    The backend code shows Couchbase Python SDK in action with Query and Search, but also how to plug together all of the elements and build an application with Couchbase Server and the Python SDK.

    Collections and Scope are set immediately after opening the bucket:

    cluster = Cluster(CONNSTR, ClusterOptions(authenticator))
    static_bucket = cluster.bucket('travel-sample')
    default_collection = static_bucket.default_collection()
        dynamic_bucket = cluster.bucket('travel-users')
    except BucketMissingException as e:
        print("Collections bucket not found.")
        print("Have you initialized it with the script?")
        raise e  # Continue raising error so application halts
    scope = dynamic_bucket.scope('userData')
    user_collection = scope.collection('users')
    flight_collection = scope.collection('flights')

    And operations are now performed on the specific collection, rather than the whole bucket (or the whole bucket via _default collection, as in Server 6.5 without the Developer Preview enabled).

    booked_flights = rv.content_as[list](0)
        rows = []
        for key in booked_flights:
        respjson = jsonify({"data": rows})