You can use the delete() method to delete a single object or a group of objects. When deleting data, Cloud DB will delete the corresponding data based on the input object primary key and does not check whether other attributes of the object are consistent with the stored data. The delete operation is atomic. That is, all objects in the list either are deleted successfully or fail to be deleted.
When calling the data deletion method, there are two ways to return the result: either by returning a Promise object or by passing a callback object in the parameters. The following example explains the Promise approach in detail.
Precautions:
Objects to be deleted in a batch must belong to the same object type. Otherwise, the delete operation will fail.
Sample code:
When you delete objects, the number of deleted objects will be returned if the deletion succeeds; otherwise, an exception will be thrown.
async delete() {
try {
let book = new BookInfo();
book.id = 1;
let deleteNum = await databaseZone.delete(book);
console.info(`Succeeded in deleting , result: ` + JSON.stringify(deleteNum));
} catch (err) {
console.error(`Failed to delete , Code: ${err.code}, message: ${err.message}`);
}
}