Antony
Antony

Reputation: 976

Marklogic - Trouble with mem-node-replace

I am using mem:node-replace for replacing the content.But it is taking too much of time.I got a time-out error. Is there any alternative for this?

Find the Sample Xquery:

xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";
import module namespace mem = "http://xqdev.com/in-mem-update" 
  at '/MarkLogic/appservices/utils/in-mem-update.xqy';


let $uri := cts:uri-match((concat('*',$id ,'*')),(),cts:collection-query($collection))
let $data := doc($uri)
let $final := mem:node-replace($data//title[@id='2'],doc($uri1)//title[@id='2'])
return (
  xdmp:document-insert('/test/sample.xml',$final)
)

Upvotes: 2

Views: 1041

Answers (1)

Mads Hansen
Mads Hansen

Reputation: 66783

mem:node-replace() is not the most efficient way to modify content.

If your documents are already in the database, and you simply want to replace a node, then there is no need to use the in-mem-update library.

You should use xdmp:node-replace().

For more complex transformations you might also consider the following options for in-memory transforms:

  • Ryan Dew has a similar library https://github.com/ryanjdew/XQuery-XML-Memory-Operations that performs much better. It has functions that provide a similar style of coding to the in-mem-update library.
  • XSLT performs extremely well. You can use xdmp:xslt-eval() with a local XSLT variable, or xdmp:xslt-invoke() with an XSLT that has been loaded into the Modules database. It is a little different programming style, but can often outperform and be developed more simply using a modified identity transform as a "push style" stylesheet with specific templates for the changes you need to make.
  • A recursive typeswitch

If you need to modify an extremely large number of documents, then you still may start to run into timeout issues if you attempt to do it all in a single module execution.

You should look to manage bulk document changes with batch tools, such as:

Upvotes: 5

Related Questions