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.


Original document
{ "_id" : "000001"; "a" : 1 }
Example code
Document document = MapRDB.newDocument()
  .set("b", 2);
public void replace(String tablePath, Document document) {
    try(Table table = MapRDB.getTable(tablePath)) {
    } 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