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 key-value (kv) interface is the fastest way to perform operations involving single documents.
{version-common}@sdk:shared:partial$documents.adoc
upsert(String docid, Object document)
insert(String docid, Object document)
replace(String docid, Object document)
get(String docid)
remove(String docid){version-common}@sdk:shared:partial$documents.adoc
{version-common}@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: link:devguide:example$java/DocumentsExample.java[role=include]or N1QL UPDATE to update documents based on specific query criteria: update `travel-sample`.inventory.airline SET sale_price = msrp * 0.75 WHERE msrp < 19.95; |
{version-common}@sdk:shared:partial$documents.adoc
SELECT * FROM `travel-sample`.inventory.airport USE KEYS ["airport_1254"];or
SELECT * FROM `travel-sample`.inventory.airport WHERE META().id = "airport_1254";You can also retrieve parts of documents using sub-document operations, by specifying one or more sections of the document to be retrieved
link:devguide:example$java/DocumentsExample.java[role=include]{version-common}@sdk:shared:partial$documents.adoc
link:devguide:example$java/DocumentsExample.java[role=include]You can simplify by importing decrementOptions() statically:
collection.binary().decrement(counterDocId, decrementOptions().delta(5));{version-common}@sdk:shared:partial$documents.adoc
link:devguide:example$java/DocumentsExample.java[role=include]{version-common}@sdk:shared:partial$documents.adoc
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-common}@sdk:shared:partial$documents.adoc