bhp
bhp

Reputation: 11

How to generate custom _id values for CLOUDANT database?

I am trying to insert Employee record in cloudant using their Java API.

When I insert the record, Cloudant is generating its own _ID automatically. I would like to control generation of this _ID field as well.

I searched the API, but couldn't find anything like a SEQUENCE in RDBMS. Can someone give hint on how to achieve this?

Upvotes: 0

Views: 1352

Answers (2)

Dimitry Khan
Dimitry Khan

Reputation: 195

While creating your document if you pass _id within your JSON it will be created as per that. If _id is not present then it will be created automatically.

For example, This will create _id as you provide (AAA1) { "_id":"AAA1", "fname":"Dimitry", "country":"India" }

and this will generate _id automatically { "fname":"Dimitry", "country":"India" }

Upvotes: 0

Glynn Bird
Glynn Bird

Reputation: 5637

Using the Cloudant Java library, use the save method to allow you to specify the id of your documents:

https://github.com/cloudant/java-cloudant#comcloudantclientapidatabasesaveobjectwritequorum

The underlying HTTP API is documented here:

https://docs.cloudant.com/document.html#documentCreate

Upvotes: 3

Related Questions