Community

MarkLogic 10 and Data Hub 5.0

Latest MarkLogic releases provide a smarter, simpler, and more secure way to integrate data.

Read Blog →

Company

Stay On Top Of Everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up →

 
Knowledgebase:
Mass updates: "node-replace" vs "document-insert"
31 August 2020 06:04 PM

Updates are a key aspect of data manipulation in MarkLogic Server, and can sometimes be performance intensive, especially if performed in bulk. Therefore one should take time to consider exactly how your application will perform updates. Moreover, a given document often is associated with data other than its content, such as attributes, permissions, collections, quality, and metadata - all of these attributes can be affected by a chosen update method.

MarkLogic Server offers various methods to update a document, but there are two major ways to do it, in general:

  • node-replace - Replaces a node in an existing document
  • document-insert - Inserts an entirely new document into the database or replaces the content of an existing document based on whether or not a document with a specified URI already exists.

Although there is no material difference between node-replace and document-insert, using node-replace for updates is better because it preserves document attributes like permissions, collections, quality and metadata as opposed to document-insert which replaces all the aforementioned attributes along with the content of the document unless these attributes are explicitly found and attached to the insert query.

Note: Using ‘node-replace’ is the authoritative way of updating documents among all the node-level update functions

Mass-updates:

For updating a small set of documents where it is important to preserve all attributes of a document, ‘node-replace’ would be a better choice as it saves the overhead of finding the existing attributes by yourself. On the other hand, if query performance holds a higher priority over preserving the existing attributes of a document, ‘document-insert’ would likely be a better choice as it is faster when used without querying for the attributes. There is, however, no significant difference between the two if used in a similar fashion.

(1 vote(s))
Helpful
Not helpful

Comments (0)