DocumentMutation.setNull()
Either creates a new field in a document and gives the field a null value, or replaces the value of an existing field with a null value.
Operations Performed
- If the field exists, changes its value to null.
- If the field does not exist, creates the field and give it a null value.
Permissions Required
- The
readAce
andwriteAce
permissions on the volumes where the JSON tables that contain the documents are located. For information about how to set permissions on volumes, see Setting/Modifying Whole Volume ACEs. readperm
andwriteperm
on the specified field, if this field exists. See How to Obtainreadperm
andwriteperm
on a Field.writeperm
on the parent field, if the specified field does not exist. See How to Obtainreadperm
orwriteperm
on a Field.
Link to Javadoc
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);