{"pageProps":{"post":{"mdxSource":"var Component=(()=>{var d=Object.create;var c=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var r=a=>c(a,\"__esModule\",{value:!0});var k=(a,s)=>()=>(s||a((s={exports:{}}).exports,s),s.exports),N=(a,s)=>{r(a);for(var t in s)c(a,t,{get:s[t],enumerable:!0})},g=(a,s,t)=>{if(s&&typeof s==\"object\"||typeof s==\"function\")for(let n of u(s))!m.call(a,n)&&n!==\"default\"&&c(a,n,{get:()=>s[n],enumerable:!(t=h(s,n))||t.enumerable});return a},b=a=>g(r(c(a!=null?d(p(a)):{},\"default\",a&&a.__esModule&&\"default\"in a?{get:()=>a.default,enumerable:!0}:{value:a,enumerable:!0})),a);var l=k((S,o)=>{o.exports=_jsx_runtime});var x={};N(x,{default:()=>w,frontmatter:()=>y});var e=b(l()),y={title:\"Couchbase Database: Everything you need to know\",heading:\"Couchbase Database: Everything you need to know\",\"//\":null,date:\"2023-10-22\",tags:[\"database\"],draft:!1,summary:\"Discover how Couchbase stands out from other databases, understand what does Couchbase do, and learn about its advantages and drawbacks. Explore Couchbase data types, data modelling best practices, and how to create and retrieve data using indexes.\",authors:[\"usmanakhtar\"],newsletterActionText:\"Keep yourself in the know with the most recent articles on Couchbase and other databases\"};function f(a={}){let{wrapper:s}=a.components||{};return s?(0,e.jsx)(s,Object.assign({},a,{children:(0,e.jsx)(t,{})})):t();function t(){let n=Object.assign({div:\"div\",h2:\"h2\",a:\"a\",span:\"span\",p:\"p\",ol:\"ol\",li:\"li\",strong:\"strong\",h3:\"h3\",ul:\"ul\",blockquote:\"blockquote\",code:\"code\",pre:\"pre\"},a.components),{Image:i}=n;return i||v(\"Image\",!0),(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(\"div\",{className:\"w-full pt-10\",children:(0,e.jsx)(n.div,{children:(0,e.jsx)(i,{alt:\"couchbase\",src:\"/static/images/database/featured/couchbase.png\",width:\"808\",height:\"278\"})})}),(0,e.jsxs)(n.h2,{id:\"couchbase\",children:[(0,e.jsx)(n.a,{href:\"#couchbase\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),\"Couchbase:\"]}),(0,e.jsx)(n.p,{children:\"Couchbase is a widely used NoSQL database management system that is known for its high performance, scalability, and flexibility. It belongs to the category of distributed, document-oriented databases and is frequently utilized in the development of modern, data-intensive applications.\"}),(0,e.jsxs)(n.h2,{id:\"characteristics\",children:[(0,e.jsx)(n.a,{href:\"#characteristics\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),\"Characteristics:\"]}),(0,e.jsx)(n.p,{children:\"Here are some key characteristics and features of Couchbase:\"}),(0,e.jsxs)(n.ol,{children:[(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"NoSQL Database\"}),\": Couchbase is a NoSQL database, which means it doesn't rely on the traditional relational database model. Instead, it offers a flexible schema, making it suitable for handling unstructured or semi-structured data.\"]}),(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Distributed Architecture\"}),\": Couchbase is designed to be distributed across multiple nodes or servers. This architecture ensures high availability, fault tolerance, and scalability.\"]}),(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"N1QL Query Language\"}),': Couchbase provides a query language called N1QL (pronounced \"nickel\") that allows you to perform SQL-like queries on JSON documents. This makes it easier for developers who are familiar with SQL to work with Couchbase.']}),(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Full-Text Search\"}),\": Couchbase offers full-text search capabilities, allowing you to perform complex searches on JSON documents. This feature is beneficial for applications that require powerful search functionality.\"]}),(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Cross-Datacenter Replication\"}),\": Couchbase supports cross-datacenter replication, enabling you to replicate data between different data centers or geographic regions. This is crucial for disaster recovery and maintaining low-latency access for users in different parts of the world.\"]}),(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Integrated Caching\"}),\": Couchbase incorporates a caching layer that can significantly reduce database read latency by keeping frequently accessed data in memory.\"]}),(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Transactions:\"}),\" Couchbase transactions provide support for ACID properties, ensuring the integrity of protected actions on the database.\"]})]}),(0,e.jsxs)(n.h2,{id:\"main-concepts\",children:[(0,e.jsx)(n.a,{href:\"#main-concepts\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),\"Main Concepts:\"]}),(0,e.jsx)(\"div\",{className:\"w-full\",children:(0,e.jsx)(n.div,{children:(0,e.jsx)(i,{alt:\"couchbase\",src:\"/static/images/database/diagrams/couchbase.png\",width:\"808\",height:\"278\"})})}),(0,e.jsxs)(n.h3,{id:\"1-cluster\",children:[(0,e.jsx)(n.a,{href:\"#1-cluster\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),\"1. Cluster:\"]}),(0,e.jsx)(n.p,{children:\"A cluster is a group of connected Couchbase nodes that work together to store and manage data. This collaboration allows for efficient data storage, retrieval, and management. By working together, the nodes in a cluster distribute the data across multiple machines, ensuring that the data is always available and can handle errors. Additionally, nodes can be added or removed from the cluster as needed, making it easy to scale and adapt.\"}),(0,e.jsxs)(n.h3,{id:\"2-node\",children:[(0,e.jsx)(n.a,{href:\"#2-node\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),\"2. Node:\"]}),(0,e.jsx)(n.p,{children:\"In a Couchbase cluster, a node refers to an individual server or machine that is part of the distributed database system. These nodes collaborate to store and manage data, handle client requests, and maintain high availability and fault tolerance.\"}),(0,e.jsxs)(n.h3,{id:\"3-services\",children:[(0,e.jsx)(n.a,{href:\"#3-services\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),\"3. Services:\"]}),(0,e.jsx)(n.p,{children:\"Couchbase Nodes offer a range of services, including data storage, query processing, indexing, and search. Within a cluster, different types of nodes can be assigned to provide specific services. For example, data nodes are responsible for storing data, while index nodes handle indexing. It enables the independent deployment and management of various services, allowing for multi-dimensional scaling. The complete list of provided services is as follows:\"}),(0,e.jsxs)(n.ul,{children:[(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Data:\"}),\" Supports the storage, setting, and retrieval of data items by key.\"]}),(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Query:\"}),\" Parses and executes N1QL queries, interacting with the Data and Index services to return results.\"]}),(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Index:\"}),\" Creates indexes for the query service.\"]}),(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Search:\"}),\" Creates indexes for full text search, supporting language-aware searching.\"]}),(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Analytics:\"}),\" Supports resource-intensive operations like join, set, aggregation, and grouping.\"]}),(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Event:\"}),\" Supports real-time handling of changes to data.\"]}),(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Backup:\"}),\" Supports both the scheduling and the immediate execution of full and incremental data backups.\"]})]}),(0,e.jsxs)(n.h3,{id:\"4-management\",children:[(0,e.jsx)(n.a,{href:\"#4-management\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),\"4. Management:\"]}),(0,e.jsx)(n.p,{children:\"Couchbase provides tools and interfaces to manage and monitor each node in your cluster. These tools help you gain insights, make informed decisions, and optimize your Couchbase environment. With these features, you can proactively resolve issues, allocate resources efficiently, and improve the efficiency of your Couchbase cluster.\"}),(0,e.jsxs)(n.h3,{id:\"5-security\",children:[(0,e.jsx)(n.a,{href:\"#5-security\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),\"5. Security:\"]}),(0,e.jsx)(n.p,{children:\"Couchbase Server can be made very secure to protect data privacy and integrity and control access attempts. The security facilities provided include:\"}),(0,e.jsxs)(n.ul,{children:[(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Authentication:\"}),\" All individuals, including administrators, users, and applications, need to authenticate themselves in order to access the server.\"]}),(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Authorization:\"}),\" Couchbase Server uses Role-Based Access Control (RBAC) to manage access to system resources. When a user logs in, their assigned roles determine what they can access. If the roles allow the requested access, it is granted; otherwise, it is denied.\"]}),(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Auditing:\"}),\" Administrators can audit actions performed on Couchbase Server. This enables them to ensure that system-management tasks are being performed appropriately.\"]}),(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Encryption:\"}),\" Data is encrypted to ensure its security and privacy. Only authorized parties with the appropriate decryption methods can access the encoded information.\"]})]}),(0,e.jsxs)(n.h3,{id:\"6-data-storage\",children:[(0,e.jsx)(n.a,{href:\"#6-data-storage\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),\"6. Data Storage:\"]}),(0,e.jsx)(n.p,{children:\"Couchbase Server stores data in the form of a key-value pair. Each key is unique within its bucket, and values can be either binary or JSON within the buckets. There are two types of buckets used:\"}),(0,e.jsxs)(n.ul,{children:[(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Couchbase Bucket:\"}),\" Couchbase buckets exist both in memory and on disk.\"]}),(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Ephemeral Bucket:\"}),\" Ephemeral buckets exist only in memory.\"]})]}),(0,e.jsx)(n.p,{children:\"Couchbase provides data compression and Time to Live (TTL) settings for buckets, effectively managing memory quotas to ensure optimal performance and scalability. Data can be stored in memory, on disk, or both, with replication for data loss protection. Additionally, it includes an automatic caching layer for quick data access. The data in buckets is persistently stored on disk, while less frequently accessed items are asynchronously ejected from memory to free up space. Frequently accessed data is retained in memory for improved performance.\"}),(0,e.jsx)(n.blockquote,{children:(0,e.jsxs)(n.p,{children:[\"If you want to learn more about how data is inserted and updated under the hood, you can read the official documentation at \",(0,e.jsx)(n.a,{href:\"https://docs.couchbase.com/server/current/learn/buckets-memory-and-storage/memory-and-storage.html\",children:\"Memory and Storage, Couchbase Docs\"}),\".\"]})}),(0,e.jsxs)(n.h2,{id:\"example\",children:[(0,e.jsx)(n.a,{href:\"#example\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),\"Example:\"]}),(0,e.jsxs)(n.p,{children:[\"We will create two buckets, \",(0,e.jsx)(n.code,{children:\"Students\"}),\" and \",(0,e.jsx)(n.code,{children:\"Courses\"}),\". The \",(0,e.jsx)(n.code,{children:\"Students\"}),\" bucket will store information about the students, while the \",(0,e.jsx)(n.code,{children:\"Courses\"}),\" bucket will contain course details. By establishing relationships between students and courses, we try to retrieve data using joins.\"]}),(0,e.jsxs)(n.h3,{id:\"setup\",children:[(0,e.jsx)(n.a,{href:\"#setup\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),\"Setup:\"]}),(0,e.jsx)(n.p,{children:\"To set up Couchbase, we will use Docker. After installing Docker on your system, please run the following command:\"}),(0,e.jsx)(n.pre,{className:\"language-bash\",children:(0,e.jsx)(n.code,{className:\"code-highlight language-bash\",children:(0,e.jsxs)(n.span,{className:\"code-line\",children:[\"docker run -d --name db -p \",(0,e.jsx)(n.span,{className:\"token number\",children:\"8091\"}),\"-8097:8091-8097 -p \",(0,e.jsx)(n.span,{className:\"token number\",children:\"9123\"}),\":9123 -p \",(0,e.jsx)(n.span,{className:\"token number\",children:\"11207\"}),\":11207 -p \",(0,e.jsx)(n.span,{className:\"token number\",children:\"11210\"}),\":11210 -p \",(0,e.jsx)(n.span,{className:\"token number\",children:\"11280\"}),\":11280 -p \",(0,e.jsx)(n.span,{className:\"token number\",children:\"18091\"}),`-18097:18091-18097 couchbase\n`]})})}),(0,e.jsxs)(n.p,{children:[\"Now, you can access the Couchbase web console at \",(0,e.jsx)(n.a,{href:\"http://localhost:8091/\",children:\"http://localhost:8091\"}),\".\"]}),(0,e.jsxs)(n.h3,{id:\"queries\",children:[(0,e.jsx)(n.a,{href:\"#queries\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),\"Queries:\"]}),(0,e.jsx)(n.p,{children:\"Let's create both buckets. Go to the Buckets section in the web console and create both buckets as shown in the screenshot:\"}),(0,e.jsx)(\"div\",{className:\"w-full\",children:(0,e.jsx)(n.div,{children:(0,e.jsx)(i,{alt:\"couchbase\",src:\"/static/images/database/screenshots/couchbase-bucket-web-console.png\",width:\"1969\",height:\"964\"})})}),(0,e.jsx)(n.p,{children:\"When creating buckets, ensure that you do not allocate all the system resources to a single bucket. Otherwise, you will be unable to create additional buckets.\"}),(0,e.jsxs)(n.h3,{id:\"insertion\",children:[(0,e.jsx)(n.a,{href:\"#insertion\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),(0,e.jsx)(n.strong,{children:\"Insertion:\"})]}),(0,e.jsx)(n.p,{children:\"To test inserting documents into a collection, you can run queries in the Query section of the web console.\"}),(0,e.jsx)(n.pre,{className:\"language-sql\",children:(0,e.jsxs)(n.code,{className:\"language-sql code-highlight\",children:[(0,e.jsxs)(n.span,{className:\"code-line\",children:[(0,e.jsx)(n.span,{className:\"token keyword\",children:\"INSERT\"}),\" \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"INTO\"}),\" Students \",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\"(\"}),(0,e.jsx)(n.span,{className:\"token keyword\",children:\"KEY\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"VALUE\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\")\"}),`\n`]}),(0,e.jsxs)(n.span,{className:\"code-line\",children:[(0,e.jsx)(n.span,{className:\"token keyword\",children:\"VALUES\"}),`\n`]}),(0,e.jsxs)(n.span,{className:\"code-line\",children:[\" \",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\"(\"}),(0,e.jsx)(n.span,{className:\"token string\",children:'\"student:1\"'}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" {\",(0,e.jsx)(n.span,{className:\"token string\",children:'\"name\"'}),\": \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"John Doe\"'}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"age\"'}),\": \",(0,e.jsx)(n.span,{className:\"token number\",children:\"20\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"course_id\"'}),\": \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"course:101\"'}),\"}\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\")\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),`\n`]}),(0,e.jsxs)(n.span,{className:\"code-line\",children:[\" \",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\"(\"}),(0,e.jsx)(n.span,{className:\"token string\",children:'\"student:2\"'}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" {\",(0,e.jsx)(n.span,{className:\"token string\",children:'\"name\"'}),\": \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"Jane Smith\"'}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"age\"'}),\": \",(0,e.jsx)(n.span,{className:\"token number\",children:\"22\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"course_id\"'}),\": \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"course:102\"'}),\"}\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\")\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),`\n`]}),(0,e.jsxs)(n.span,{className:\"code-line\",children:[\" \",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\"(\"}),(0,e.jsx)(n.span,{className:\"token string\",children:'\"student:3\"'}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" {\",(0,e.jsx)(n.span,{className:\"token string\",children:'\"name\"'}),\": \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"Bob Johnson\"'}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"age\"'}),\": \",(0,e.jsx)(n.span,{className:\"token number\",children:\"21\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"course_id\"'}),\": \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"course:101\"'}),\"}\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\")\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\";\"}),`\n`]})]})}),(0,e.jsx)(n.pre,{className:\"language-sql\",children:(0,e.jsxs)(n.code,{className:\"language-sql code-highlight\",children:[(0,e.jsxs)(n.span,{className:\"code-line\",children:[(0,e.jsx)(n.span,{className:\"token keyword\",children:\"INSERT\"}),\" \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"INTO\"}),\" Courses \",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\"(\"}),(0,e.jsx)(n.span,{className:\"token keyword\",children:\"KEY\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"VALUE\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\")\"}),`\n`]}),(0,e.jsxs)(n.span,{className:\"code-line\",children:[(0,e.jsx)(n.span,{className:\"token keyword\",children:\"VALUES\"}),`\n`]}),(0,e.jsxs)(n.span,{className:\"code-line\",children:[\" \",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\"(\"}),(0,e.jsx)(n.span,{className:\"token string\",children:'\"course:101\"'}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" {\",(0,e.jsx)(n.span,{className:\"token string\",children:'\"name\"'}),\": \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"Mathematics\"'}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"instructor\"'}),\": \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"Professor Smith\"'}),\"}\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\")\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),`\n`]}),(0,e.jsxs)(n.span,{className:\"code-line\",children:[\" \",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\"(\"}),(0,e.jsx)(n.span,{className:\"token string\",children:'\"course:102\"'}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" {\",(0,e.jsx)(n.span,{className:\"token string\",children:'\"name\"'}),\": \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"Physics\"'}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"instructor\"'}),\": \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"Professor Johnson\"'}),\"}\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\")\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),`\n`]}),(0,e.jsxs)(n.span,{className:\"code-line\",children:[\" \",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\"(\"}),(0,e.jsx)(n.span,{className:\"token string\",children:'\"course:103\"'}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" {\",(0,e.jsx)(n.span,{className:\"token string\",children:'\"name\"'}),\": \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"Chemistry\"'}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"instructor\"'}),\": \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"Professor Adams\"'}),\"}\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\")\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),`\n`]}),(0,e.jsxs)(n.span,{className:\"code-line\",children:[\" \",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\"(\"}),(0,e.jsx)(n.span,{className:\"token string\",children:'\"course:104\"'}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" {\",(0,e.jsx)(n.span,{className:\"token string\",children:'\"name\"'}),\": \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"Biology\"'}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"instructor\"'}),\": \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"Professor Brown\"'}),\"}\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\")\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\";\"}),`\n`]})]})}),(0,e.jsxs)(n.h3,{id:\"retrieval\",children:[(0,e.jsx)(n.a,{href:\"#retrieval\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),(0,e.jsx)(n.strong,{children:\"Retrieval:\"})]}),(0,e.jsx)(n.p,{children:\"In order to retrieve documents from Bucket, you will have to create an index first, you can do so by executing a query.\"}),(0,e.jsx)(n.pre,{className:\"language-sql\",children:(0,e.jsx)(n.code,{className:\"language-sql code-highlight\",children:(0,e.jsxs)(n.span,{className:\"code-line\",children:[(0,e.jsx)(n.span,{className:\"token keyword\",children:\"CREATE\"}),\" \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"PRIMARY\"}),\" \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"INDEX\"}),\" \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"ON\"}),\" Students\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\";\"}),`\n`]})})}),(0,e.jsx)(n.p,{children:\"After successfully creating an index, you can retrieve the records as easily as in any SQL database with a simple query.\"}),(0,e.jsx)(n.pre,{className:\"language-sql\",children:(0,e.jsx)(n.code,{className:\"language-sql code-highlight\",children:(0,e.jsxs)(n.span,{className:\"code-line\",children:[(0,e.jsx)(n.span,{className:\"token keyword\",children:\"SELECT\"}),\" \",(0,e.jsx)(n.span,{className:\"token operator\",children:\"*\"}),\" \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"FROM\"}),\" Students\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\";\"}),`\n`]})})}),(0,e.jsx)(n.p,{children:\"Remember that when working with JOINs in Couchbase, you need to create appropriate indexes to support the specific JOIN conditions you're using in your queries. Index design is crucial for query performance, so be mindful of your data model and query patterns when creating indexes.\"}),(0,e.jsx)(n.pre,{className:\"language-sql\",children:(0,e.jsxs)(n.code,{className:\"language-sql code-highlight\",children:[(0,e.jsxs)(n.span,{className:\"code-line\",children:[(0,e.jsx)(n.span,{className:\"token keyword\",children:\"SELECT\"}),\" s\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\".\"}),\"name \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"AS\"}),\" student_name\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" s\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\".\"}),\"age\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" c\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\".\"}),\"name \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"AS\"}),` course_name\n`]}),(0,e.jsxs)(n.span,{className:\"code-line\",children:[(0,e.jsx)(n.span,{className:\"token keyword\",children:\"FROM\"}),\" Students \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"AS\"}),` s\n`]}),(0,e.jsxs)(n.span,{className:\"code-line\",children:[(0,e.jsx)(n.span,{className:\"token keyword\",children:\"JOIN\"}),\" Courses \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"AS\"}),\" c \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"ON\"}),\" s\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\".\"}),\"course_id \",(0,e.jsx)(n.span,{className:\"token operator\",children:\"=\"}),\" META\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\"(\"}),\"c\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\")\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\".\"}),\"id\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\";\"}),`\n`]})]})}),(0,e.jsxs)(n.p,{children:[\"When executing the query, you will encounter an error. In order to use the \",(0,e.jsx)(n.code,{children:\"join\"}),\" operation, you need to create an index first.\"]}),(0,e.jsx)(n.pre,{className:\"language-sql\",children:(0,e.jsx)(n.code,{className:\"language-sql code-highlight\",children:(0,e.jsxs)(n.span,{className:\"code-line\",children:[(0,e.jsx)(n.span,{className:\"token keyword\",children:\"CREATE\"}),\" \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"INDEX\"}),\" idx_student_courses \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"ON\"}),\" Students\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\"(\"}),\"course_id\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\")\"}),\" \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"WHERE\"}),\" course_id \",(0,e.jsx)(n.span,{className:\"token operator\",children:\"IS\"}),\" VALUED\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\";\"}),`\n`]})})}),(0,e.jsx)(n.p,{children:\"After that, try running the query again.\"}),(0,e.jsx)(n.pre,{className:\"language-sql\",children:(0,e.jsxs)(n.code,{className:\"language-sql code-highlight\",children:[(0,e.jsxs)(n.span,{className:\"code-line\",children:[(0,e.jsx)(n.span,{className:\"token keyword\",children:\"SELECT\"}),\" s\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\".\"}),\"name \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"AS\"}),\" student_name\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" s\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\".\"}),\"age\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\",\"}),\" c\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\".\"}),\"name \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"AS\"}),` course_name\n`]}),(0,e.jsxs)(n.span,{className:\"code-line\",children:[(0,e.jsx)(n.span,{className:\"token keyword\",children:\"FROM\"}),\" Students \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"AS\"}),` s\n`]}),(0,e.jsxs)(n.span,{className:\"code-line\",children:[(0,e.jsx)(n.span,{className:\"token keyword\",children:\"JOIN\"}),\" Courses \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"AS\"}),\" c \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"ON\"}),\" s\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\".\"}),\"course_id \",(0,e.jsx)(n.span,{className:\"token operator\",children:\"=\"}),\" META\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\"(\"}),\"c\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\")\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\".\"}),\"id\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\";\"}),`\n`]})]})}),(0,e.jsx)(n.p,{children:\"Now you will be able to retrieve the data.\"}),(0,e.jsx)(n.blockquote,{children:(0,e.jsxs)(n.p,{children:[\"If you want to learn more about indexes in Couchbase, you can read the official documentation at \",(0,e.jsx)(n.a,{href:\"https://docs.couchbase.com/server/current/learn/services-and-indexes/indexes/indexes.html\",children:\"Couchbase Indexes\"}),\".\"]})}),(0,e.jsxs)(n.h3,{id:\"update\",children:[(0,e.jsx)(n.a,{href:\"#update\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),(0,e.jsx)(n.strong,{children:\"Update:\"})]}),(0,e.jsx)(n.p,{children:\"The document can be updated as follows:\"}),(0,e.jsx)(n.pre,{className:\"language-sql\",children:(0,e.jsx)(n.code,{className:\"language-sql code-highlight\",children:(0,e.jsxs)(n.span,{className:\"code-line\",children:[(0,e.jsx)(n.span,{className:\"token keyword\",children:\"UPDATE\"}),\" Students \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"SET\"}),\" course \",(0,e.jsx)(n.span,{className:\"token operator\",children:\"=\"}),\" \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"course:101\"'}),\" \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"WHERE\"}),\" META\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\"(\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\")\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\".\"}),\"id \",(0,e.jsx)(n.span,{className:\"token operator\",children:\"=\"}),\" \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"student:2\"'}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\";\"}),`\n`]})})}),(0,e.jsxs)(n.h3,{id:\"delete\",children:[(0,e.jsx)(n.a,{href:\"#delete\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),(0,e.jsx)(n.strong,{children:\"Delete:\"})]}),(0,e.jsx)(n.p,{children:\"To delete a document, simply execute the following query:\"}),(0,e.jsx)(n.pre,{className:\"language-sql\",children:(0,e.jsx)(n.code,{className:\"language-sql code-highlight\",children:(0,e.jsxs)(n.span,{className:\"code-line\",children:[(0,e.jsx)(n.span,{className:\"token keyword\",children:\"DELETE\"}),\" \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"FROM\"}),\" Students \",(0,e.jsx)(n.span,{className:\"token keyword\",children:\"WHERE\"}),\" META\",(0,e.jsx)(n.span,{className:\"token punctuation\",children:\"(\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\")\"}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\".\"}),\"id \",(0,e.jsx)(n.span,{className:\"token operator\",children:\"=\"}),\" \",(0,e.jsx)(n.span,{className:\"token string\",children:'\"student:2\"'}),(0,e.jsx)(n.span,{className:\"token punctuation\",children:\";\"}),`\n`]})})}),(0,e.jsxs)(n.h2,{id:\"conclusion\",children:[(0,e.jsx)(n.a,{href:\"#conclusion\",\"aria-hidden\":\"true\",tabIndex:\"-1\",children:(0,e.jsx)(n.span,{className:\"icon icon-link\"})}),\"Conclusion:\"]}),(0,e.jsx)(n.p,{children:\"In conclusion, Couchbase is a versatile and powerful NoSQL database solution. It offers flexible schema design, high performance, and efficient query capabilities. With its ability to handle various data models and use cases, along with features like N1QL, powerful indexing, and seamless scalability, Couchbase is an excellent choice for modern applications. It empowers developers to innovate and deliver exceptional user experiences, whether for real-time analytics, interactive querying, or dynamic content. With Couchbase, you can unlock the potential of your data to drive innovation and success.\"})]})}}var w=f;function v(a,s){throw new Error(\"Expected \"+(s?\"component\":\"object\")+\" `\"+a+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return x;})();\n;return Component;","toc":[{"value":"Couchbase:","url":"#couchbase","depth":2},{"value":"Characteristics:","url":"#characteristics","depth":2},{"value":"Main Concepts:","url":"#main-concepts","depth":2},{"value":"1. Cluster:","url":"#1-cluster","depth":3},{"value":"2. Node:","url":"#2-node","depth":3},{"value":"3. Services:","url":"#3-services","depth":3},{"value":"4. Management:","url":"#4-management","depth":3},{"value":"5. Security:","url":"#5-security","depth":3},{"value":"6. Data Storage:","url":"#6-data-storage","depth":3},{"value":"Example:","url":"#example","depth":2},{"value":"Setup:","url":"#setup","depth":3},{"value":"Queries:","url":"#queries","depth":3},{"value":"Insertion:","url":"#insertion","depth":3},{"value":"Retrieval:","url":"#retrieval","depth":3},{"value":"Update:","url":"#update","depth":3},{"value":"Delete:","url":"#delete","depth":3},{"value":"Conclusion:","url":"#conclusion","depth":2}],"frontMatter":{"readingTime":{"text":"9 min read","minutes":8.255,"time":495300,"words":1651},"slug":"database/couchbase","fileName":"database/couchbase.mdx","title":"Couchbase Database: Everything you need to know","heading":"Couchbase Database: Everything you need to know","//":null,"date":"2023-10-22T00:00:00.000Z","tags":["database"],"draft":false,"summary":"Discover how Couchbase stands out from other databases, understand what does Couchbase do, and learn about its advantages and drawbacks. Explore Couchbase data types, data modelling best practices, and how to create and retrieve data using indexes.","authors":["usmanakhtar"],"newsletterActionText":"Keep yourself in the know with the most recent articles on Couchbase and other databases"}},"authorDetails":[{"readingTime":{"text":"2 min read","minutes":1.025,"time":61500,"words":205},"slug":"usmanakhtar","fileName":"usmanakhtar.md","name":"Usman Akhtar","avatar":"/static/images/usmanakhtar-avatar.png","occupation":"Software Engineer","email":"contact@usmanakhtar.dev","twitter":"https://twitter.com/usmakhtar","linkedin":"https://www.linkedin.com/in/usmakhtar","github":"https://github.com/usmanakhtar-dev","description":"Experienced software engineer with a passion for building elegant and efficient solutions to complex problems. Committed to continuously learning and adapting to new technologies and techniques.","date":null}],"prev":{"title":"How to Test Your Microservices with Spring Cloud Contracts","heading":"How to Test Your Microservices with Spring Cloud Contracts","date":"2023-07-01T00:00:00.000Z","tags":["contract-testing"],"draft":false,"summary":"Explore the advantages of contract testing with Spring Boot Cloud Contract testing framework. Learn through practical examples in this blog on how and why to use Spring Cloud Contracts for effective contract testing.","authors":["usmanakhtar"],"repoName":"/tree/main/How%20to%20Test%20Your%20Microservices%20with%20Spring%20Cloud%20Contracts","newsletterActionText":"Boost your testing skills with the latest methods and tools, keeping your code robust and ready for success","slug":"testing/spring-cloud-contracts"},"next":null},"__N_SSG":true}