A newer version of this documentation is available.

View Latest

Deleting documents

You can delete documents by using the lcb_remove() function.

The following example shows how to delete a document:

static void on_removed(lcb_t instance, const void *cookie, lcb_error_t err,
   const lcb_remove_resp_t *resp) {

  if (err != LCB_SUCCESS) {
      fprintf(stderr, "Failed to remove item: %s\n", lcb_strerror(instance, err));
  }
}

static void deleteDoc() {
  // ...
  lcb_set_remove_callback(instance, on_removed);
  lcb_remove_cmd_t cmd = { 0 };
  const lcb_remove_cmd_t *cmdlist = &cmd;
  cmd.v.v0.key = "deleteme";
  cmd.v.v0.nkey = strlen("deleteme");
  err = lcb_remove(instance, NULL, 1, &cmdlist);
  if (err != LCB_SUCCESS) {
    printf("Couldn't schedule remove operation: %s\n", lcb_strerror(instance, err));
  } else {
    lcb_wait(instance);
  }
}