Couchbase Essentials
()
About this ebook
- Learn how to install and configure Couchbase Server.
- Explore Couchbase Servers’ extensive key/value API with examples from several popular programming languages.
- Apply Map/Reduce techniques and patterns to find data in your Couchbase Server documents
This book is for those application developers who want to achieve greater flexibility and scalability from their software. Whether you are familiar with other NoSQL databases or have only used relational systems, this book will provide you with enough background to move you along at your own pace. If you are new to NoSQL document databases, the design discussions and introductory material will give you the information you need to get started with Couchbase.
John Zablocki
John Zablocki is a Developer Advocate at Couchbase. He is the organizer of Beantown ALT.NET and a former adjunct at Fairfield University. John holds an M.S. in Computer Science from Rensselaer Hartford. He has worked at startups throughout his career and is interested in the intersection of .NET and open source. Online, John can be found at http://about.me/johnzablocki. Offline, he can be found too infrequently around Boston, with his dog Lady, daughter MaryKatherine, and his Martin acoustic.
Related to Couchbase Essentials
Related ebooks
Building Scalable Apps with Redis and Node.js Rating: 0 out of 5 stars0 ratingsImplementing Cloud Design Patterns for AWS Rating: 0 out of 5 stars0 ratingsInstant Apache ActiveMQ Messaging Application Development How-to Rating: 0 out of 5 stars0 ratingsRESTful Web API Design with Node.js - Second Edition Rating: 1 out of 5 stars1/5Hands-On Microservices with Kubernetes: Build, deploy, and manage scalable microservices on Kubernetes Rating: 5 out of 5 stars5/5Practical OneOps Rating: 0 out of 5 stars0 ratingsLearning Couchbase Rating: 0 out of 5 stars0 ratingsElasticsearch Essentials Rating: 0 out of 5 stars0 ratingsGoogle Cloud Platform All-In-One Guide: Get Familiar with a Portfolio of Cloud-based Services in GCP (English Edition) Rating: 0 out of 5 stars0 ratingsLearning RabbitMQ Rating: 0 out of 5 stars0 ratingsInstant Redis Optimization How-to Rating: 0 out of 5 stars0 ratingsElasticSearch Cookbook - Second Edition Rating: 0 out of 5 stars0 ratingsApache Pulsar in Action Rating: 0 out of 5 stars0 ratingsSpark GraphX in Action Rating: 0 out of 5 stars0 ratingsHBase in Action Rating: 0 out of 5 stars0 ratingsAdvanced Platform Development with Kubernetes: Enabling Data Management, the Internet of Things, Blockchain, and Machine Learning Rating: 0 out of 5 stars0 ratingsCI/CD Pipeline with Docker and Jenkins: Learn How to Build and Manage Your CI/CD Pipelines Effectively (English Edition) Rating: 0 out of 5 stars0 ratingsAWS Glue Second Edition Rating: 0 out of 5 stars0 ratingsMongoDB in Action: Covers MongoDB version 3.0 Rating: 0 out of 5 stars0 ratingsCloud Architects A Complete Guide - 2019 Edition Rating: 0 out of 5 stars0 ratingsKafka Streams - Real-time Streams Processing Rating: 5 out of 5 stars5/5Kafka in Action Rating: 0 out of 5 stars0 ratingsPodman in Action: Secure, rootless containers for Kubernetes, microservices, and more Rating: 0 out of 5 stars0 ratingsSpark in Action Rating: 0 out of 5 stars0 ratingsMicroservices with .Net Core Complete Self-Assessment Guide Rating: 0 out of 5 stars0 ratingsInstant Pentaho Data Integration Kitchen Rating: 0 out of 5 stars0 ratingsFull Stack GraphQL Applications: With React, Node.js, and Neo4j Rating: 0 out of 5 stars0 ratings
Databases For You
Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Access 2019 For Dummies Rating: 0 out of 5 stars0 ratingsPractical Data Analysis Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Access 2010 All-in-One For Dummies Rating: 4 out of 5 stars4/5CompTIA DataSys+ Study Guide: Exam DS0-001 Rating: 0 out of 5 stars0 ratingsLearn SQL in 24 Hours Rating: 5 out of 5 stars5/5Learn SQL Server Administration in a Month of Lunches Rating: 3 out of 5 stars3/5Blockchain Basics: A Non-Technical Introduction in 25 Steps Rating: 5 out of 5 stars5/5Behind Every Good Decision: How Anyone Can Use Business Analytics to Turn Data into Profitable Insight Rating: 5 out of 5 stars5/5Learning PostgreSQL Rating: 1 out of 5 stars1/5Python Projects for Everyone Rating: 0 out of 5 stars0 ratingsExcel 2021 Rating: 4 out of 5 stars4/5The AI Bible, Making Money with Artificial Intelligence: Real Case Studies and How-To's for Implementation Rating: 4 out of 5 stars4/5Getting Started with SQL Server 2014 Administration Rating: 0 out of 5 stars0 ratingsData Science Strategy For Dummies Rating: 0 out of 5 stars0 ratingsDatabase Management for Business Leaders: Building and Using Data Solutions That Work for You Rating: 0 out of 5 stars0 ratingsSpring in Action, Sixth Edition Rating: 5 out of 5 stars5/5Pro DAX with Power BI: Business Intelligence with PowerPivot and SQL Server Analysis Services Tabular Rating: 0 out of 5 stars0 ratingsUbuntu Server Cookbook Rating: 0 out of 5 stars0 ratingsQuery Store for SQL Server 2019: Identify and Fix Poorly Performing Queries Rating: 0 out of 5 stars0 ratingsNeo4j - A Graph Project Story Rating: 5 out of 5 stars5/5Use LibreOffice Base: A Beginners Guide Rating: 0 out of 5 stars0 ratingsOracle DBA Mentor: Succeeding as an Oracle Database Administrator Rating: 0 out of 5 stars0 ratingsMySQL Administrator's Bible Rating: 5 out of 5 stars5/5MDM for Customer Data: Optimizing Customer Centric Management of Your Business Rating: 0 out of 5 stars0 ratingsAccess 2016 For Dummies Rating: 0 out of 5 stars0 ratings
Reviews for Couchbase Essentials
0 ratings0 reviews
Book preview
Couchbase Essentials - John Zablocki
Table of Contents
Couchbase Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Getting Comfortable with Couchbase
The NoSQL landscape
NoSQL taxonomies
Installing Couchbase
Installing Couchbase on Linux
Installing Couchbase on Windows
Installing Couchbase on Mac OS X
Ports
Running Couchbase for the first time
Exploring the Couchbase Console
Couchbase architecture
Couchbase clusters
Replication
Balancing and rebalancing
Couchbase SDKs
RAM matters
Summary
2. Using Couchbase CRUD Operations
The Couchbase SDKs
Basic operations
Connecting to your cluster
Creating and updating a record
Reading and deleting records
Advanced CRUD operations
Temporary keys
Appending and incrementing data
Storing complex types
Concurrency and locking
Asynchronous operations
Durability operations
Summary
3. Creating Secondary Indexes with Views
Couchbase documents
Couchbase indexes
MapReduce
Map functions
Reduce functions
Couchbase MapReduce
Basic mapping
Basic reducing
Couchbase views
Couchbase Console
Development views
Design documents
Creating a view
Querying views
Grouping
Key queries
Eventual consistency
Couchbase SDKs and views
Summary
4. Advanced Views
Querying by type
Nested collections
Range queries
Multiple keys per document
Compound indexes
Grouping keys
Emitting values
Querying with beer-sample
Querying all documents by type
Counting breweries by location
Finding beer documents by brewery
Collated views
Summary
5. Introducing N1QL
Installing N1QL
Simple queries
Null or missing properties
String utilities
Aggregation and math
Complex structures
Working with collections
Joins
SDK support
Summary
6. Designing a Schema-less Data Model
Key design
Keys, metadata, and RAM
Predictable keys
Unpredictable keys
Storing keys
Key restrictions
Document design
Denormalization
Object-to-document mappings
Data types
Document separation
Object schemas
Schema-less structure changes
Object and document properties
Document relationships
Finalizing the schema
Summary
7. Creating a To-do App with Couchbase
A simple to-do schema
Working with SDKs
A brief overview of MVC
Using SDK clients
Creating a task
Listing tasks
Showing only incomplete tasks
Nested tasks
Summary
A. Couchbase SDKs
Couchbase Java SDK
Current version
How to obtain it
The basics
Couchbase .NET SDK
Current version
How to obtain it
The basics
Couchbase PHP SDK
Current version
How to obtain it
The basics
The Couchbase Node.js SDK
Current version
How to obtain it
The basics
Couchbase Python SDK
Current version
How to obtain it
The basics
Couchbase Ruby SDK
Current version
How to obtain it
The basics
Couchbase C SDK
Current version
How to obtain it
Index
Couchbase Essentials
Couchbase Essentials
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: February 2015
Production reference: 1200215
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-449-3
www.packtpub.com
Credits
Author
John Zablocki
Reviewers
Roy Enjoy
Philip Hanson
Aleksandar Mićović
Chris Wilkinson
Commissioning Editor
Pramila Balan
Acquisition Editors
Richard Gall
Richard Brookes-Bland
Content Development Editor
Kirti Patil
Technical Editors
Shashank Desai
Rikita Poojari
Copy Editor
Vikrant Phadke
Project Coordinator
Nidhi Joshi
Proofreaders
Safis Editing
Maria Gould
Paul Hindle
Indexer
Rekha Nair
Production Coordinator
Nilesh R. Mohite
Cover Work
Nilesh R. Mohite
About the Author
John Zablocki is the director of information technology at EF High School Exchange Year in Cambridge, Massachusetts, USA. Previously, he worked at Couchbase Inc. as a developer advocate, maintaining the .NET SDK and delivering training to customers and users alike. John is the author of O'Reilly's Orchard CMS. He is a frequent presenter at community events and has run Code Camps and user groups. He holds a Master's degree in computer science from Rensselaer at Hartford, where he became an enthusiast of open source technology. John can be approached online at http://about.me/johnzablocki and around Cambridge with his daughter, Mary Katherine; his dog, Lady; and his Fender Jaguar.
About the Reviewers
Roy Enjoy started to improve his geeky skills with a Commodore 64, some QBasic, and lots of Boulderdash. Then, the Internet exploded after bulletin board systems. Since it is always a shovel man who gets paid first in a gold rush, he decided to thrive within web technologies.
After finishing courses in a couple of IT-oriented schools and playing with a large number of different languages, frameworks, and databases, he worked in different parts of the world, including India, Australia, Turkey, the Netherlands, and Serbia. He is currently living in Australia, and he is trying to learn 3D animation / VFX programming and computer-generated imagery these days.
As an open source evangelist, Roy maintains an API documentation and source code search engine for the Python programming language, named pydoc.net, which is also an open source project.
Philip Hanson is a full-time professional software developer with a diverse background ranging from micro-ISV SaaS to capital-e enterprise development. He continues to experiment with new languages, techniques, and approaches to solve the world's problems.
Aleksandar Mićović started programming at the age of 12. Many years later, he graduated from the University of Toronto with a degree in computer science. Today, he's a professional software engineer and consultant in Belgrade, Serbia, with clients spanning across the globe. When he's not working, he enjoys cooking, reading, and traveling. You can contact him at http://aleksandarmicovic.com/.
Chris Wilkinson has spent years in the software development industry after attaining a degree in Computer Games Programming at the University of Teesside. After making the move into business IT upon leaving the university, Chris has worked all over the world, developing Java applications for businesses in many verticals, including finance, aerospace, and the public sector. Specialized in web and big data technologies, Chris now manages the development team for Askaris Information Technology, a new start-up business developing software for some of the largest oilfield drilling companies in the world.
www.PacktPub.com
Support files, eBooks, discount offers, and more
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Free access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
Preface
Not too long ago, I was fortunate enough to have worked for Couchbase Inc. with the developer solutions team. In my role as a developer advocate, I had two primary responsibilities: maintaining the Couchbase .NET SDK and training Couchbase users on how to develop for Couchbase Server.
During my tenure on the SDK team, I worked with hundreds of developers around the world who were using Couchbase Server for a wide variety of solutions. Some were using Couchbase Server for its distributed caching abilities, while others needed a model that could support near-real-time analytics over a flexible schema. I was always impressed with Couchbase Server's ability to handle such a vast number of development scenarios.
Through the countless meetings I had with the development community and customers alike, it became clear to me that NoSQL is far from a technology fad. Along with cloud computing and mobile services, NoSQL has become a part of the fabric from which modern applications are woven.
As with relational databases before them, NoSQL databases such as Couchbase Server are quickly nearing the required knowledge
status for application developers. Modern applications that need to reach a massive scale or require greater data model flexibility have found success with non-relational systems.
It is a tremendous opportunity to be able to share my experience at Couchbase with you, the reader. This is an exciting technology, and this book contains the tools you need to get started with Couchbase development.
What this book covers
Chapter 1, Getting Comfortable with Couchbase, introduces Couchbase Server and provides details on obtaining and installing it. It also walks you through setting up Couchbase Server for the first time.
Chapter 2, Using Couchbase CRUD Operations, provides an overview of basic Couchbase Server operations. Basic SDK usage is demonstrated while exploring the various CRUD API methods.
Chapter 3, Creating Secondary Indexes with Views, explains in detail the programming model of MapReduce. After this exploration, the basics of using MapReduce within Couchbase Server are explored.
Chapter 4, Advanced Views, explores common view patterns for Couchbase development, following on the previous chapter's discussion of MapReduce.
Chapter 5, Introducing N1QL, introduces the prerelease Couchbase query language, N1QL.
Chapter 6, Designing a Schema-less Data Model, discusses many of the design options that must be considered when building Couchbase Server applications. Both key/value and document schemas are covered.
Chapter 7, Creating a To-do App with Couchbase, provides an overview on how to convert Couchbase Server to a basic to-do application.
Appendix, Couchbase SDKs, contains a brief introduction to the official Couchbase SDKs, including installation and basic usage.
What you need for this book
In order to follow along with the examples in this book, you will need to install Couchbase Server 3.0.x. Installer packages are available for Windows, Mac OS X, and multiple Linux distributions. Couchbase Server comes in both Community and Enterprise editions, and either will work.
The SDK examples shown in this book mostly use the .NET and Couchbase Server SDKs, though any SDK can be used. To try out the SDK samples, you will need to have a development environment for your chosen language and the SDK itself. Details on where to obtain and install both the server and the clients are provided early in the book.
Who this book is for
This book is for those application developers who want greater flexibility and scalability for their software. Whether you are familiar with other NoSQL databases or have used only relational systems, this book will provide you with enough background for you to proceed at your own pace. If you are new to NoSQL document databases, the design discussions and introductory material will give you the information you need to get started with Couchbase.
Conventions
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and explanations of their meanings.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: To update an existing document, we use the replace operation.
A block of code is set as follows:
function(doc, meta) {
emit(meta.id, null);
}
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
function(doc, meta) { if (doc.type == beer
) {
emit(null, null);
}
}
Any command-line input or output is written as follows:
./cbq-engine–couchbase http://localhost:8091
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like