【问题标题】:Load the CSV file in to the content Database with collection using corb使用 corb 将 CSV 文件加载到内容数据库中
【发布时间】:2018-05-13 20:16:11
【问题描述】:

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

【问题讨论】:

    标签: marklogic marklogic-corb


    【解决方案1】:

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

    属性文件如下所示:

    # 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 选项,例如权限和集合。在以前的 MarkLogic 版本中,权限和集合是第三个和第四个参数。根据您使用的 MarkLogic 版本调整对xdmp:document-insert() 的调用(文档左上角有一个下拉菜单可以选择您的版本)。

    【讨论】:

      猜你喜欢
      • 2015-10-02
      • 2014-10-07
      • 1970-01-01
      • 2016-04-17
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 1970-01-01
      • 2021-10-02
      相关资源
      最近更新 更多