Cloudant Fundamentals: The _id

Unlocking the mysteries of the unique _id field (part 2 of 10)

Glynn Bird
May 14, 2018 · 3 min read
The document _id is unique across the database. Photo by Rahul Shanbhag on Unsplash

I want my auto-incrementing values back

If you’re used to relational databases, you may be familiar with auto-incrementing primary keys. The key starts at “1” for the first record and the number increments each time — easy! With Cloudant, you either get Cloudant to generate a unique id for you, or you create your own. If you want your document’s ids to be “1”, “2”, “3” etc, it’s up to you to keep track of where you’re up to!

How do I generate my own unique identifier

There are libraries that can generate unique identifiers for you such as the uuid package for Node.js:

Can I edit an _id once it’s in the database?

Although you can edit a document body, you can’t change a document’s id. There’s nothing stopping you deleting the unwanted document and creating a new one. You can even do both the delete and the insert operations at the same time using a POST /db/_bulk_docs request.

Next time

In the next post, we’ll unlock the mysteries of the _rev token.


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.