Cloudant Fundamentals: Programmatic CRUD

Friendly syntax for Node.js, Python, and Java (part 6 of 10)

Glynn Bird
Jun 11, 2018 · 2 min read
  1. a Jupyter notebook using the pixiedust_node library
  2. a text file
Photo by Max Nelson on Unsplash

Connect to the database

First we need a URL containing our Cloudant credentials and to start up the library:

Create the database

Creating a database is as simple as calling the create function:

Creating documents

Let’s say we want to add an array of documents to our database:

Reading documents

Documents can be read back singly by specifying the ID of the document you want:

Updating documents

The cloudant-quickstart library allows documents to be updated without worrying about revision tokens: just pass in the new document body and the library will figure it out:

Deleting a document

A documents can be removed from the database by passing an ID delete function:

Where did the rev token go?

The cloudant-quickstart library hides the rev token from you. The rev token is a tricky concept for new starters, so this library abstracts it from you so that you can get on with building something quickly. In a production environment, you will have to get to grips with revision tokens, but for now we can sit back and relax.

Next time

In the next post we’ll look at querying data. Until then!

IBM CODAIT

Things we made with data at IBM’s Center for Open Source Data and AI Technologies.

Glynn Bird

Written by

Developer @ IBM. https://glynnbird.com

IBM CODAIT

Things we made with data at IBM’s Center for Open Source Data and AI Technologies.