The Data Model
Couchbase’s use of JSON as a storage format allows powerful search and query over documents. Several data structures are supported by the SDK, including map, list, queue, and set.
These pages cover the Beta release of the Couchbase Python SDK. The API interface is stable, but could change for bug fixes during the Beta process. New features are likely to be added.
Documentation is incomplete, subject to change, and could contain broken links.
The power to search, query, and easily work with data in Couchbase, comes from the choice of JSON as a storage format. Non-JSON storage is supported — see the Binary Storage Documentation — including UTF-8 strings, raw sequences of bytes, and language specific serializations, however, only JSON is supported by Query. In Couchbase, JSON’s key-value structure allows the storage of collection data structures such as lists, maps, sets and queues — see below. JSON’s tree-like structure allows operations against specific paths in the Document, and efficient support for these data structures.
Data structures in Couchbase are similar in concept to data structures in C# (.NET):
Map is like .NET
Dictionary<TKey, TValue>, and is a key-value structure, where a value is accessed by using a key string.
List is like a .NET
List<TValue>and is a sequential data structure. Values can be placed in the beginning or end of a list, and can be accessed using numeric indexes.
Queue is like a
IQueueimplementation which offers FIFO (first-in-first-out) semantics, allowing it to be used as a lightweight job queue.
Set is a wrapper over a
List<TValue>which provides the ability to handle unique values.
These data structures are stored as JSON documents in Couchbase, and can therefore be accessed using N1QL and normal key-value operations. Data structures can also be manipulated using the traditional sub-document and full-document KV APIs.
Using the data structures API may help your application in two ways:
Simplicity: Data structures provide high level operations by which you can deal with documents as if they were container data structures. Adding an item to a dictionary is expressed as
MapAdd, rather than retrieving the entire document, modifying it locally, and then saving it back to the server.
Efficiency: Data structure operations do not transfer the entire document across the network. Only the relevant data is exchanged between client and server, allowing for less network overhead and lower latency.