Partial document updates with MarkLogic’s REST API

Author: Dave Cassel  |  Category: Software Development

I just got my first taste of one of the new features in MarkLogic 7: the ability to do partial document updates through the built-in REST API. It made me happy.

You may be aware that the REST API was introduced in MarkLogic 6. That version handles search and full-document CRUD operations. However, if you wanted to supplement a document with a little piece of information, you had two choices:

  1. maintain the entire document on the client side, update it there, then PUT the entire document to /v1/documents, replacing the entire document
  2. write an extension to the REST API that could do a more surgical update

I tended to do the second. MarkLogic 7 includes an new feature that provides a third choice:

  1. send a PATCH command to /v1/documents, specifying what the update should be

Deleting a comment

I’ve been working on a demo that has event data. When you click on an event, you can record a comment on it. My next task was to let the user delete a comment, which I can specify within an event by an id on the comment. The site is implemented using AngularJS, so here’s the code:

That’s it. Not a line of XQuery needed, just out-of-the-box functionality. Cool.

I’ll update this post with a link to the documentation when MarkLogic 7’s released.

Tags: , ,

Leave a Reply