Chapter 4. Getting Data In and Out
With Couchbase Server installed, and your chosen client library up and running, it is time to start storing and retrieving information into the database. All of the client libraries use the same basic operations, although they may have different function or methods names. Despite the differences that exist between individual client libraries, the basic operations and how and why you use them are the same.
A basic list of the key Create, Retrieve, Update, and Delete (CRUD) operations is shown in Table 4-1.
Table 4-1. Key CRUD operations
| Operation | Description |
|---|---|
add(id, document [, expiry]) | Add an item if ID doesn’t already exist |
set(id, document [, expiry]) | Store a document with ID |
replace(id, document [, expiry]) | Update the document for an existing ID |
cas(id, document, check [, expiry]) | Update the document for an existing ID providing the check matches |
get(id) | Get the specified document |
incr(id [, offset]) | Increment the document value by offset |
decr(id [, offset] | Decrement the document value by offset |
append(id, value) | Append the content to the end of the current document |
prepend(id, value) | Prepend the content to the beginning of the current document |
delete(id) | Delete the specified document |
There are, though, common use cases and sequences with the different operations that can be used to achieve different processes and solutions. Let’s look at some of these in the context of a typical web application.
Basic Interface
To start, let’s look at a basic Ruby script that ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access