Skip to Content
Developing with Couchbase Server
book

Developing with Couchbase Server

by MC Brown
February 2013
Intermediate to advanced
88 pages
2h 7m
English
O'Reilly Media, Inc.
Content preview from Developing with Couchbase Server

Chapter 5. Storing and Updating Recipes

Now that we’ve looked at the document design and the core storage and retrieval methods, let’s look at some specific code examples using our recipe data.

Creating your document and storing it are straightforward. Depending on your client language you can model the data and use serialization to create the JSON structure.

Initial Storage

Storing your initial document requires creating the document structure (as described above), and then using a set() operation to store the data into the database using an appropriate document ID, such as a UUID.

For example:

$recipe = array('title' => 'Lasagne', 'subtitle' => 'Traditional italian pasta dish', 'servings' => 4);
$cb = new Couchbase("127.0.0.1:8091", "recipes", "", "recipes");
$cb->set(uniqid(),$recipe);

To get the best results out of the Couchbase when it comes to querying and extracting data using views, JSON should be used as the storage format.

Most languages support some form of serialization of an internal object into an external format. Sometimes this is just for the purposes of external storage (for example on disk), but more complex solutions exist for object relational modeling (ORM), where an internal object is translated into RDBMS based storage.

With Couchbase Server an alternative model is available, with internal objects being serializable into the JSON format, which allows integration with the built-in document model, views and indexing.

Within the PHP client library there ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Getting Started with Couchbase Server

Getting Started with Couchbase Server

MC Brown
Pro Couchbase Server, Second Edition

Pro Couchbase Server, Second Edition

David Ostrovsky, Mohammed Haji, Yaniv Rodenski
Couchbase Essentials

Couchbase Essentials

John C Zablocki

Publisher Resources

ISBN: 9781449331153Errata Page