Skip to content

Latest commit

 

History

History
125 lines (85 loc) · 3.48 KB

documents.adoc

File metadata and controls

125 lines (85 loc) · 3.48 KB

Document

project-docs:partial$attributes.adoc

Couchbase supports CRUD operations, various data structures, and binary documents.

Although query and path-based (Sub-Document) services are available, the simplicity of the document-based kv interface is the fastest way to perform operations involving single documents.

{version-server}@sdk:shared:partial$documents.adoc

Primitive Key-Value Operations

upsert(docid, document)
insert(docid, document)
replace(docid, document)
get(docid)
remove(docid)

{version-server}@sdk:shared:partial$documents.adoc

{version-server}@sdk:shared:partial$documents.adoc

Note

If you wish to only modify certain parts of a document, you can use sub-document operations which operate on specific subsets of documents:

collection.mutate_in("customer123", [SD.upsert("fax", "311-555-0151")])

or N1QL UPDATE to update documents based on specific query criteria:

update `default` SET sale_price = msrp * 0.75 WHERE msrp < 19.95;

{version-server}@sdk:shared:partial$documents.adoc

SELECT * FROM default USE KEYS ["docid"];

or

SELECT * FROM default WHERE META(default).id = "docid";

You can also retrieve parts of documents using sub-document operations, by specifying one or more sections of the document to be retrieved

name, email = cb.retrieve_in('user:kingarthur', 'contact.name', 'contact.email')

{version-server}@sdk:shared:partial$documents.adoc

>>> cb.counter('counter_id', delta=20, initial=100).value
100L
>>> cb.counter('counter_id', delta=1).value
101L
>>> cb.counter('counter_id', delta=-50).value
51L

{version-server}@sdk:shared:partial$documents.adoc

rv = cb.get('counter_id')
value, cas = rv.value, rv.cas
if should_increment_value(value):
  cb.upsert('counter_id', value + increment_amount, cas=cas)

{version-server}@sdk:shared:partial$documents.adoc

Use Cases

The SDK provides a high-level abstraction over the simple incr()/decr() of Couchbase Server’s memcached binary protocol, using collections.binary(). This enables you to work with counters using get() and upsert() operations — allowing, inter alia, the use of durability options with the operations. You will find several ways of working with counters in the API docs.

{version-server}@sdk:shared:partial$documents.adoc