使用corb将CSV文件加载到包含集合的内容数据库中

时间:2018-05-13 20:16:12

标签: marklogic marklogic-corb

我的本​​地文件夹中有一个CSV文件。我想使用CoRB将该文件加载到MarkLogic DB中到指定的Collection中。你能帮忙吗?

1 个答案:

答案 0 :(得分:1)

您可能希望将作业配置为使用指向CSV的URIS-FILE选项。 CORB将读取文件并将CSV中的每一行发送到配置的PROCESS-MODULE作为要处理的$URI值。

属性文件看起来像这样:

# how to connect to to the XCC server
XCC-CONNECTION-URI=xcc://user:password@localhost:8202/
# path to the CSV file to be processed
URIS-FILE=input-uris.csv 
# the module that will process and save each CSV row
PROCESS-MODULE=save-row.xqy|ADHOC
# how many threads to use to execute process modules
THREAD-COUNT=10 

在您的流程模块中,您需要声明一个名为$URIS的外部变量,然后通过分隔符对CSV行进行标记并处理数据列。调用xdmp:document-insert()以插入文档并指定您希望文档所在的集合:

xquery version "1.0-ml";

declare variable $URI as xs:string external;

let $columns := fn:tokenize($URI, ",\s?")
(: assuming that the first column has a unique value to be used for the URI :)
let $uri := $columns[1]
(:do whatever processing you would need to generate the document from CSV columns :)
let $content := $columns[2] 
return 
  xdmp:document-insert($uri,
    $content, 
    map:map() => map:with("collections", "mySpecialCollection")
  )

注意: xdmp:document-insert()的签名最近已更改。现在指定xdmp:document-insert个选项,例如权限和集合,在第三个参数中的map或options元素中。在以前的MarkLogic版本中,权限和集合是第三个和第四个参数。根据您使用的MarkLogic版本调整xdmp:document-insert()的调用(文档左上角有一个下拉列表,用于选择您的版本)。

相关问题