如何在查询控制台标记逻辑中设置集合

duo*_*one 2 marklogic

我是标记逻辑的新手。我想在查询控制台中创建一个带有集合的 json 文件。怎么做?我已经在名为“Test”的 marklogic 服务器中创建了一个数据库。而且我还插入了没有集合的 serval json 文件。如何使用 XQuery 或其他方法设置集合?

Mad*_*sen 5

如果您已经创建了文档,您可以使用xdmp:document-set-collectionsxdmp:document-add-collections功能在文档上设置集合。

搜索文档的 URI,然后设置您想要的任何集合:

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

您可以在将文档保存到数据库时设置集合和权限xdmp:document-insert,方法是在 options 参数中指定它。

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>)
Run Code Online (Sandbox Code Playgroud)