Create a Couchbase Document without Specifying an ID

Using the UUID without the toString() method seems to be working. (I am storing the value to a String variable instead.) Hopefully, I am not overlooking anything that will come back to bite me later on.

import com.couchbase.client.java.Bucket
import com.couchbase.client.java.Cluster
import com.couchbase.client.java.CouchbaseCluster
import com.couchbase.client.java.document.json.JsonObject
import com.couchbase.client.java.document.JsonDocument

Cluster myCluster = CouchbaseCluster.create()
Bucket myBucket = myCluster.openBucket(“myBucketName”)
String docId = UUID.randomUUID()

// …verify that the document ID is unique in the bucket…

docJson = JsonObject.empty()
.put(“myKey”, “myValue”)
doc = JsonDocument.create(docId, docJson)
JsonDocument insertedDoc = bucket.insert(doc, 500, TimeUnit.MILLISECONDS) // Specify the timeout to prevent TimeoutExceptions