Table.update()

Applies to an OJAI document the updates that are contained in a DocumentMutation object.

Operations Performed

Verifies whether a document with the specified ID exists.
  • If a document with the ID does not exist, the document is created.
  • If a document with the ID does exist, the mutation is applied to the document. The type of mutation depends on the kind of DocumentMutation being set as part of the update.

Example

Original Document
{
	"_id" : "movie0000001",
	"title" : "OJAI -- The Documentary",
	"studio" : "MapR Technologies, Inc.",
	"release_date" : "2015-09-29",
	"trailers" : {
		"teaser" : "https://10.10.21.90/trailers/teaser",
		"theatrical" : "https://10.10.21.90/trailers/theatrical"
	},
	"characters" : [
		"Heroic Developer", 
           "Evil Release Manager", 
           "Mad Development Manager"
	],
	"box_office_gross" : 1000000000L
}
Example Code for the update
public DocumentMutation buildDocumentMutation() {
    return MapRDB.newDocumentMutation()
      .increment("box_office_gross", 1000000000L);
  }
public void update(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 with the change in bold
{
	"_id" : "movie0000001",
	"title" : "OJAI -- The Documentary",
	"studio" : "MapR Technologies, Inc.",
	"release_date" : "2015-09-29",
	"trailers" : {
		"teaser" : "https://10.10.21.90/trailers/teaser",
		"theatrical" : "https://10.10.21.90/trailers/theatrical"
	},
	"characters" : [
		"Heroic Developer", 
           "Evil Release Manager", 
           "Mad Development Manager"
	],
	"box_office_gross" : 2000000000L
}

Permissions Required

Link to Javadoc

Table