DocumentMutation.delete()

Deletes the field at the specified path with the OJAI DocumentMutationinterface. The DocumentMutation interface defines the APIs that perform mutations of a document already stored in a DocumentStore.

Operations Performed

Deletes the field without first checking whether the field exists. All fields below the deleted field are also deleted, even if the application does not have write permission on the subfields. The only exception is if a column family is defined on a subfield. In this case, the column family persists and remains accessible.

If the field does not exist, this method silently returns without doing anything.

Example of Deleting a Scalar Field

Original Document
{ 
  "_id" : "000001",
  "a" : {
         "b" : 1,
         "c" : 3 
         }
} 
Example Code for the deletion
public DocumentMutation buildDocumentMutation() {
    return MapRDB.newDocumentMutation()
      .delete("a.c");
  }

  public void deleteField(String tablePath, DocumentMutation mutation, String _id) {
    try(Table table = MapRDB.getTable(tablePath)) {
      table.update(_id, mutation);
    }
  }
Parameter Description
_id The value of the document's _id field.
tablePath The path of the table in the MapR file system. See the "Table Paths" section in MapR-DB JSON Tables.
Revised Document
{ 
  "_id" : "000001",
  "a" : {
         "b" : 1
         }
}

Permissions Required

Link to Javadoc

DocumentMutation

Important: If a DocumentMutation object modifies a field two or more times, only the final operation on that field is applied.

Example One

table.update() in the last line fails with error code 22:

DBDocument doc = MapRDB.newDocument()
        .set("int", 100)
        .set("date", new Date(1000))
        .set("string", "a string");

table.insertOrReplace("doc1", doc);

// Set different fields
DocumentMutation mutation = MapRDB.newDocumentMutation();
mutation.setOrReplace("string", 1000);
mutation.set("string", 2000);

table.update("doc1", mutation);

Example Two

This code results in the document {"string":"a string add3"}, rather than the document {"string":"a string add1 add2 add3"}.

DBDocument doc = MapRDB.newDocument()
        .set("string", "a string");

table.insertOrReplace("doc1", record);

DocumentMutation mutation = MapRDB.newDocumentMutation();
mutation.append("string", " add1");
mutation.append("string", " add2");
mutation.append("string", " add3");

table.update("doc1", mutation);