简体   繁体   English

将文档插入特定的数据库MarkLogic

[英]Insert a document into a particular database MarkLogic

I'm setting up a database with roxy, which is different from the "documents" database. 我正在使用roxy建立一个数据库,该数据库不同于“文档”数据库。 I want to insert a config file into that database. 我想将配置文件插入该数据库。

I have this function in xquery ml-1.0 我在xquery ml-1.0中具有此功能

xquery version "1.0-ml";



declare namespace appsetup = "http://kittens.com.au/appsetup";



declare function appsetup:setup-day0($root,$content-db){
    (: some values :)
    let $m := map:new ()
    let $_ := map:put ($m, "Kittens-Forever",xdmp:parse-dateTime("[Y0001]-[M01]-[D01]", "2999-12-31"))
    let $_ := map:put ($m, "Kittens-Never", xdmp:parse-dateTime("[Y0001]-[M01]-[D01]", "1899-12-31"))
    let $_ := map:put ($m, "Kittens-Load-Root", $root)

    return  xdmp:document-insert ("/ksys/smap", <s:map>{$m}</s:map>,
                    (xdmp:permission ("Kittens-role", "read"),
                    xdmp:permission ("Kittens-role", "update")) )

};

The xdmp:document-insert inserts the document in to the default "documents" database. xdmp:document-insertxdmp:document-insert默认的“ documents”数据库。 I had a look around, and i couldn't find a way to say load this document into this database. 我四处张望,找不到找到将文档加载到该数据库的方法。 I only found a way to insert the document into a particular forest with xdmp:document-load ( https://docs.marklogic.com/xdmp:document-load ). 我只找到了一种使用xdmp:document-load( https://docs.marklogic.com/xdmp:document-load )将文档插入特定森林的方法。

Is there a way for me to say load this thing into this database, preferably just as a xquery parameter? 我有什么办法说可以将此东西加载到此数据库中,最好只是作为xquery参数加载吗?

xdmp:document-insert does not insert into the Documents database by default. xdmp:document-insert默认情况下不会插入到Documents数据库中。 It inserts into the database defined in the application server configuration. 它将插入到应用程序服务器配置中定义的数据库中。 The idea is that you have an application server that you use to interface with the database. 这个想法是您有一个用于与数据库接口的应用程序服务器。

Some notes: 一些注意事项:

  • Use an app server configured for your database. 使用为您的数据库配置的应用服务器。
  • Or use the REST API that has a parameter for this 或者使用具有此参数的REST API
  • Or use HTTP rewrite rules to dynamically change the database based on a user, URI or query parameter 或使用HTTP重写规则根据用户,URI或查询参数动态更改数据库
  • Or use xdmp:eval or its derivatives (spawn, invoke, invoke-function) which all have an option to define which database to use. 或使用xdmp:eval或其衍生版本(生成,调用,调用功能),它们都具有定义要使用的数据库的选项。

For your particular sample, I would suggest that you use xdmp:invoke-function. 对于您的特定示例,我建议您使用xdmp:invoke-function。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM