4
votes

I want to know if anyone has experience of deleting millions of documents in Marklogic? At the moment I used the simple xqueries to fetch the document uri s which need to be deleted and then I use corb to batch the whole operation.

Is there a faster way to delete millions of documents once I have a list of Uris ?

3

3 Answers

4
votes

There are several ways to tackle this. The first question is how you retrieve the document uri's? Best approach for that is using the URI lexicon, and cts:uris or cts:uri-match. Second is how you perform the delete. You could iterate over the found uri's, and call xdmp:document-delete for each, but you might consider skipping all above, and revert to xdmp:collection-delete alltogether. That seems to work very efficient. It does require you to have a unique collection label assigned, and it can be delete entirely..

HTH!

3
votes

Calling xdmp:spawn or xdmp:spawn-function might be a little faster than corb, simply because it avoids a network round-trip.

If the documents are organized for it, xdmp:collection-delete or xdmp:directory-delete could also be faster. But the collections or directories should be around 1,000-100,000 documents each, ideally.

Finally if you want to get rid of everything, it would be much faster to clear the forest or the database. It could even be faster to export the stuff you want to keep (using XQSync perhaps), clear the database, and then re-import.

1
votes

Note also that if you have directory creation enabled that deletes are vastly slower. If you do not need direcgtories (only really needed for WEBDAV) I suggest not using directories then deletes will be much faster.