Deepak Saini
Deepak Saini

Reputation: 103

how to move existing documents from one collection to another within the same database/forest in Marklogic

Can someone please suggest some way to move existing documents from one collection (or the default one) to another within the same database/forest in MarkLogic.

Upvotes: 2

Views: 512

Answers (2)

Tyler Replogle
Tyler Replogle

Reputation: 1339

You'll want to Re-insert the documents at the same uri but add the new/different collection.

You'll want to query the documents using something like cts:search() and then do a xdmp:document-insert(), the 4th parameter is where you put the collection(s).

If it's a lot of do documents you'll want to batch this up in sizes from 10 to 1,000 depending on the size of the documents, if you aren't sure 100 is a good starting place.

If this is a really big amount use corb2.

Upvotes: 1

Will Goring
Will Goring

Reputation: 1040

You can use the function xdmp:document-set-collections() to set the collections a document is in without reinserting it. If you just want to make specific changes, xdmp:document-add-collections() and xdmp:document-remove-collections() can be used to add or remove some collections without modifying the rest.

Like Tyler said, you'll want to batch it up or use corb if there are a lot of documents you want to process.

Upvotes: 7

Related Questions