Within Couchbase Server, the techniques and systems used to get information into and out of the database differ according to the level and volume of data that you want to access. The different methods can be identified according to the base operations of create, retrieve, update and delete.
Information is stored into the database using the memcached protocol interface to store a value against a specified key . Bulk operations for setting the key/value pairs of a large number of documents at the same time are available, and these are more efficient than multiple smaller requests.
To retrieve information from the database, there are two methods available: By Key and By View
- By Key
If you know the key used to store a particular value, then you can use the memcached protocol (or an appropriate memcached compatible client-library) to retrieve the value stored against a specific key. You can also perform bulk operations.
- By View
If you do not know the key, you can use the View system to write a view that outputs the information you need. The view generates one or more rows of information for each JSON object stored in the database. The view definition includes the keys (used to select specific or ranges of information) and values. For example, you could create a view on contact information that outputs the JSON record by the contact's name, and with a value containing the contacts address. Each view also outputs the key used to store the original object. If the view doesn't contain the information you need, you can use the returned key with the memcached protocol to obtain the complete record.
To update information in the database, you must use the memcached protocol interface. The memcached protocol includes functions to directly update the entire contents, and also to perform simple operations, such as appending information to the existing record, or incrementing and decrementing integer values.
To delete information from Couchbase Server, you need to use the memcached protocol which includes an explicit delete command to remove a key/value pair from the server.
However, Couchbase Server also permits information to be stored in the database with an expiry value. The expiry value states when a key/value pair should be automatically deleted from the entire database, and can either be specified as a relative time (for example, in 60 seconds), or absolute time (31st December 2012, 12:00pm).