Couchbase works as a NoSQL database. So, we will first know about NoSQL Databases. NoSQL Databases use a variety of data models for accessing and managing data, optimized for large data volume, low latency and flexible data models.
Features of NoSQL Database
- Flexibility: Enables faster and more iterative development.
- Scalability: NoSQL databases are designed to scale out by using distributed clusters.
- High-performance: Enable higher performance and provide similar functionality with relational databases.
- Highly functional: Provide highly functional APIs.
Types of NoSQL Database
- key-value: Databases are highly partition-able and allow horizontal scaling at scales.
- Document: Data is represented often as an object or JSON-like document.
- Graph: A graph database’s purpose is to make it easy to build and run applications that work with highly connected datasets.
- In-memory: It is basically used for gaming.
- Search: Many applications output logs to help developers troubleshoot issues.
Introduction to Couchbase
Couchbase Server is an open-source, distributed, NoSQL document-oriented engagement database. It exposes a fast key-value store with managed cache for sub-millisecond data operations, purpose-built indexers for fast queries and a powerful query engine for executing SQL-like queries, by default it runs on port 8091.
- Flexible Data Model
Couchbase Specific Keywords
- BUCKET: It is a data container used in Couchbase server. Basically, it is collection of all related documents. Every BUCKET has its associated properties like its size, replication and persistence which can be configured.
- DOCUMENT: It stores data in the form of Key-Value pair and it is uniquely identified by a DOCUMENT_ID. Couchbase does not allow to creation two documents with the same ID.
Features of Couchbase
Couchbase Server is specialized to provide low-latency data management for large-scale interactive web, mobile, and IOT applications. Common requirements that Couchbase Server was designed to satisfy include:
- Flexible data model
- Powerful query language
- Simple administrator
- High Availability
How to install Couchbase on Ubuntu?
We will install Couchbase using apt. The Advanced Package Tool (
apt) provides the simplest and most comprehensive way to install Couchbase Server on Ubuntu. This method involves downloading and installing a small meta package from Couchbase, which
apt can then use to automatically download and install Couchbase Server and all of its dependencies.
- Download the meta-package.
curl -O https://packages.couchbase.com/releases/couchbase-release/couchbase-release-1.0-amd64.deb
- Install the meta-package.
sudo dpkg -i ./couchbase-release-1.0-amd64.deb
- Reload the local package database.
sudo apt-get update
- Install Couchbase Server.
sudo apt-get install couchbase-server
- Open a web browser and access the Couchbase Web Console to verify that the installation was successful and that the node is available.
Querying in Couchbase
Type of Indexes
- Primary Index
CREATE PRIMARY INDEX 'indexname'ON 'bucketname';
- Secondary Index
CREATE INDEX 'indexname'ON'bucketname' WHERE type='name';
We can use queries in Couchbase to fetch data, but PRIMARY INDEX is required to fetch the data from DOCUMENT.
SELECT * from Couchbase_Demo;
Services provided by Couchbase
As you can see in the left bar of the image given above, there are some of the services provided by Couchbase given as under:
- Data: Supports the storing, setting, and retrieving of data-items, specified by key.
- Query: Parses queries specified in the N1QL query-language, executes the queries, and returns results. The Query Service interacts with both the Data and Index services.
- Index: Creates indexes, for use by the Query Service.
- Eventing: Supports near real-time handling of changes to data: code can be executed both in response to document-mutations, and as scheduled by timers.
- Search: Creates indexes specially purposed for Full Text Search. This supports language-aware searching; allowing users to search for, say, the word beauties, and additionally obtain results for beauty and beautiful.
- Backup: Supports both the scheduling and the immediate execution of full and incremental data backups, either for specific individual buckets, or for all buckets on the cluster. Also allows the scheduling and immediate execution of merges of previously made backups.
- Analytics: Supports join, set, aggregation, and grouping operations; which are expected to be large, long-running, and highly consumptive of memory and CPU resources.
NoSQL databases give you the ability to read and write massive amounts of data at substantially low latency and substantially low cost compared to RDBMS. In this blog, we have learned what is Couchbase, and how to install and query in Couchbase. Stay connected to learn in detail by clicking here.