Table.replace()

Replaces a document in a table with the specified document.

To update an OJAI document, you do not have to create a copy of that document, make your changes, and then replace the original with the new copy. However, there might be situations in which you might want to replace a document if the replacement contains numerous substantial differences.

Operations Performed

Verifies whether a document with the specified ID exists.
  • If a document with the ID does not exist, returns an error.
  • If a document with the ID does exist, replaces the document.

Example

Original Document
{ "_id" : "000001"; "a" : 1 }
Example Code
Document document = MapRDB.newDocument()
  .setId("000001")
  .set("b", 2);
public void replace(String tablePath, Document document) {
    try(Table table = MapRDB.getTable(tablePath)) {
      table.replace(document);
    } catch (DocumentNotFoundException e) {
      System.out.printf("Document with _id %s does not exist in table %s\n",
          document.getId(), tablePath);
    }
  }
Replacement Document
{ "_id" : "000001"; "b" : 2 }

Permissions Required

Link to Javadoc

Table