24/7 Customer Support
13Jun 2017

0

337

0

Couchbase server

Couchbase Server

Couchbase Server

 

The couch base server 4. 5 providing the powerful new features that make it so simple for the enterprise with deep SQL experience and relational database technology. It enhanced its breakthRough SQL-based query language, including many features:

Graphical Tools for visually exploring the data model

Building the ad-hoc queries.

Advanced security

Faster queries

The following document contains a sub-document which is accessible via the field ‘tags’:

{
   “blog” : “NoSQLGeek”,
   “url” : “http://nosqlgeek.org”,
   “tags” : {
       “couchbase” : [“Couchbase Server”, “Couchbase Mobile”, “Couchbase”],
         “nosql” : [“NoSQL”, “Document Database”, “Key Value Store”],
         “mobile” : [“Couchbase Lite”, “SyncGateway”]
   }
}

 

 

With earlier Couchbase versions (<4.5) the update of a document had to follow the following pattern:

Get the whole updated document

Updated document on the client side (e.g. Updating a few properties)

Write the whole document back

A simple Java code example would be:

JsonDocument doc = bucket.get(“example::key”);
doc.content().put(“blog”, “NoSQLGeek”);
doc.content().put(“URL”, “http://nosqlgeek.org”);
bucket.replace(doc);

Latest version of Couchbase Server is 4.5

The new sub-document API is a server side feature which allows you to (surprise, surprise) only get or modify a sub-document of an existing document in Couchbase. The advantages are:

  • Better usability on the client side
    • CRUD operations can be performed based on paths
    • In cases where the modification doesn’t rely on the previous value, you can update a document without the need to fetch it up front
    • You can easier maintain key references between documents
  • Improved performance
    • It saves network bandwidth and has improved latency because you don’t need to transfer the whole document over the wire

The sub-document API also allows you to get or modify inner values or arrays of a (sub-)document.

  • Lookup operations: queries for the specific path of the document, e.g. GET, EXISTS
  • Mutation operations: Modification of multiple paths in a document, e.g. UPSERT, ARRAY_APPEND, COUNTER

The updated document can now follow the following pattern:

Our Java example would now be simplified to:

bucket.mutateIn(“example::key”)
      .replace(“blog”, “NoSQLGeek”)
      .replace(“url”, “http://nosqlgeek.org”)
      .execute();

 

 

Optimistic “locking”

Which literally means that you can change your existing document and handle it in your way. The value changes as soon as a document is modified on the server side.

  • Specific CAS valued document
  • Change the properties on the client side
  • Try to change the document by passing the old CAS value with the existing document. If the CAS value changed in between on the server side then you know that someone else modified the document in between and so you can retry to apply your changes.

So, due to an optimistic approached CAS you can apply your changes and handle it on the other hand, in a pessimistic approach the document once locked cannot be changed by anyone else again until you release its lock.

So, CAS is used for an optimistic locking approach. It’s optimistic because you expect that you can apply your changes and you handle the case that wasn’t possible because someone else changed it before. A pessimistic approach would be to lock the document upfront and so no one else can write it until this lock will be released again.

Hope, this article is useful for you! Stay tuned with us

Comments (0)