Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Bulk delete documents based on a pattern Marklogic/java script

I'm trying to bulk delete documents based on a pattern but, since the collection contains 500K plus documents, the forloop seem to get hung. Below is my code:

for (const uri of cts.uris("", null, cts.jsonPropertyValueQuery("source", "survey"))) {
  xdmp.documentDelete(uri);
}

Can somebody help me with a better way to delete documents in MarkLogic when there is large volume?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Attempting a "boil the ocean" type query to modify a really large set of documents in a single transaction is likely to run into limits, either in execution time, transaction size, expanded tree cache, etc.

It is best to break out the work into smaller units.

One easy way is to spawn the work into multiple transactions that get executed on the task server. You can do this rather easily in XQuery with xdmp:spawn-function() (unfortunately, the equivalent function is not available in SJS):

xquery version "1.0-ml";
for $URI in cts:uris("", (), cts:json-property-value-query("source", "survey"))
return xdmp:spawn-function(function(){ xdmp:document-delete($URI) })

You could modify the code above to delete subsets of URIs, instead of one at a time. However, those delete transactions should execute very quickly (and in parallel for as many threads as you have configured for the task server), so it may not be worth the hassle of more complicated code.

Another option is to use a batch tool, such as CoRB

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!