use of com.ibm.watson.language_translator.v3.model.DeleteDocumentOptions in project cloudant-java-sdk by IBM.
the class DeleteDoc method main.
public static void main(String[] args) {
// 1. Create a client with `CLOUDANT` default service name ============
Cloudant client = Cloudant.newInstance();
// 2. Delete the document =============================================
// Set the options to get the document out of the database if it exists
String exampleDbName = "orders";
String exampleDocId = "example";
GetDocumentOptions documentInfoOptions = new GetDocumentOptions.Builder().db(exampleDbName).docId(exampleDocId).build();
try {
// Try to get the document if it previously existed in the database
Document document = client.getDocument(documentInfoOptions).execute().getResult();
// Delete the document from the database
DeleteDocumentOptions deleteDocumentOptions = new DeleteDocumentOptions.Builder().db(exampleDbName).docId(// docId is required for DELETE
exampleDocId).rev(// rev is required for DELETE
document.getRev()).build();
DocumentResult deleteDocumentResponse = client.deleteDocument(deleteDocumentOptions).execute().getResult();
if (deleteDocumentResponse.isOk()) {
System.out.println("You have deleted the document.");
}
} catch (NotFoundException nfe) {
System.out.println("Cannot delete document because " + "either \"orders\" database or the \"example\" " + "document was not found.");
}
}
Aggregations