Warm tip: This article is reproduced from serverfault.com, please click

How to set collections in query console marklogic

发布于 2020-11-30 17:17:51

I am new to marklogic. I want to create a json file with a collection in query console. How to do that? I've already create a database in marklogic server named "Test". And I also inserted serval json files without collections. How to set the collections using XQuery or other methods?

Questioner
duolanierduone
Viewed
0
Mads Hansen 2020-12-01 22:01:16

If you have already created the documents, you can set the collection on the documents with xdmp:document-set-collections or xdmp:document-add-collections functions.

Search for the URIs of the documents and then set whatever collection you want:

let $uris := cts:uri-match("*.json")
return xdmp:document-set-collections($uris, "my-collection")

You can set collections and permissions when saving documents to the database with xdmp:document-insert by specifying it in the options parameter.

xdmp:document-insert(
    "/example.xml",
    <a>aaa</a>,
    <options xmlns="xdmp:document-insert">  
      <permissions>{xdmp:default-permissions()}</permissions>
      <collections>{
        <collection>/my/additional/collection</collection>,
        for $coll in xdmp:default-collections()
        return <collection>{$coll}</collection>
      }</collections>
    </options>)