Reputation: 1133
I know how to insert document in xml file but not knowing how store xquery file into Marklogic Module database. The reason I want store xquery file to setup schedule task. I have a xquery file below. Thanks in advance.
declare namespace...
let $uris := cts:element-value(...code...),
cts:and-query((...code...))
let $result := {<stats><top-docs>
for $uri in $uris[1 to 10]
...more code here..
}</top-docs></stats>
let $permissions := (xdmp:permission(..give permissions here.))
let $_ := xdmp:log("Inserting Stats Document")
return xdmp:document-insert("/acitivity/stats.xml",$result, $permissions))
Upvotes: 2
Views: 760
Reputation: 793
There's a handy recipe on the MarkLogic website as well. I use this fairly often. It's well commented and has logic to try it without a commit first to make sure it's doing what you expect:
http://developer.marklogic.com/recipe/load-a-module
Upvotes: 0
Reputation: 3732
In addition to Mads answer:
You must set execute permission on the document for a non-admin to execute it. It is important to remember that when running in marklogic (as xquery or javascript or as the result of one of the client apis) -- there are multiple databases associated with your session -- Data, Modules, Security etc -- all 'data like' operations go to the Data DB, all 'execute' operations goto the 'Modules' DB (or filesystem) etc. since there isn't a "database" parameter to xdmp:document-insert, and the database association is not changeable in a single expression -- you use one of the xdmp:eval / xdmp:invoke functions to run the insert in a sub-context that has the desired settings.
Example: https://docs.marklogic.com/xdmp:invoke-function
Upvotes: 0
Reputation: 3609
There's a number of ways to insert an xqy file into the modules database. Here are just a few:
Upvotes: 5