user2708013
user2708013

Reputation: 417

how to document insert with the collections in Marklogic using XQuery

I have a requirement where in I have to insert documents with name 1 to 6 with extension .xml, set the collection as "flags" to each of the documents in one go, and insert them into a directory called America.

How can I achieve this using xdmp:document-insert?

Upvotes: 1

Views: 456

Answers (1)

Mads Hansen
Mads Hansen

Reputation: 66723

This is a minimal example that inserts the 6 documents and sets the "flags" collection with dummy content <doc/>.

for $i in (1 to 6)
let $uri := "/America/"||$i||".xml"
return 
  xdmp:document-insert($uri, <doc/>, 
    <options xmlns="xdmp:document-insert">
      <collections>
        <collection>flags</collection>
      </collections>
    </options>)

with the URIs:

  • /America/1.xml
  • /America/2.xml
  • /America/3.xml
  • /America/4.xml
  • /America/5.xml
  • /America/6.xml

Upvotes: 3

Related Questions