2

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?

1 Answer 1

5

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>)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.