Search code examples
marklogic

Error while importing a file from a local file system to MarkLogic


I am trying to import a xml file from my local file system to MarkLogic forest. But I am getting some errors. Tried 2 versions of xdmp:document-load queries.

1st Query

xdmp:document-load("C:\Users\admin-rp\Documents\myFile.xml",
   <options xmlns="xdmp:document-load">
      <uri>/myDocs/myDocument.xml</uri>
      <permissions>{xdmp:default-permissions()}</permissions> 
      <collections>{xdmp:default-collections()}</collections> 
      <repair>full</repair>
      <forests>
        <forest>{xdmp:forest("data-hub-FINAL-1")}</forest>
      </forests>
    </options> )

Output

[1.0-ml] XDMP-PLACEKEYSLOCKING: xdmp:document-load("C:\Users\admin-rp\Documents\myFile.xml", <options xmlns="xdmp:document-load"><uri>/myDocs/myDocument.xml</uri>...</options>) -- Fast locking cannot be used with place keys. Stack Trace At line 1 column 1: In xdmp:eval(" xdmp:document-load("C:\Users\admin-rp\Documents\myFile.xml...", (), <options xmlns="xdmp:eval"><database>6682922067126681120</database>...</options>)

  1. xdmp:document-load("C:\Users\admin-rp\Documents\myFile.xml",
  2. <options xmlns="xdmp:document-load">
  3. <uri>/myDocs/myDocument.xml</uri>

2nd Query

xdmp:document-load("C:\Users\admin-rp\Documents\myFile.xml",
  map:map() 
    => map:with("uri", "/documents/myFiles.xml")
    => map:with("permissions", 
                (xdmp:default-permissions("objects"),
                 xdmp:permission("admin", "read", "object")))
    => map:with("collections", ("DDE_ASN_Booking"))
    => map:with("repair", "full")
    => map:with("forests", (xdmp:forest("data-hub-FINAL-1")))

)

Output

[1.0-ml] XDMP-INVOPTVAL: xdmp:document-load("C:\Users\admin-rp\Documents\myFile.xml", map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>)) -- Invalid option value: option 'permissions' has unexpected value '<sec:permission xmlns:sec="http://marklogic.com/xdmp/security"> sec:capabilityread</sec:capability> sec:role-id16742763111021671912</sec:role-id> </sec:permission> <sec:permission xmlns:sec="http://marklogic.com/xdmp/security"> sec:capabilityupdate</sec:capability> sec:role-id3680293911625886504</sec:role-id> </sec:permission> <sec:permission xmlns:sec="http://marklogic.com/xdmp/security"> sec:capabilityread</sec:capability> sec:role-id3680293911625886504</sec:role-id> </sec:permission> <sec:permission xmlns:sec="http://marklogic.com/xdmp/security"> sec:capabilityupdate</sec:capability> sec:role-id5126952842460325403</sec:role-id> </sec:permission> <sec:permission xmlns:sec="http://marklogic.com/xdmp/security"> sec:capabilityread</sec:capability> sec:role-id7089338530631756591</sec:role-id> </sec:permission> <sec:permission xmlns:sec="http://marklogic.com/xdmp/security"> sec:capabilityupdate</sec:capability> sec:role-id7066700860632287285</sec:role-id> </sec:permission> <sec:permission xmlns:sec="http://marklogic.com/xdmp/security"> sec:capabilityread</sec:capability> sec:role-id7066700860632287285</sec:role-id> </sec:permission> <sec:permission xmlns:sec="http://marklogic.com/xdmp/security"> sec:capabilityupdate</sec:capability> sec:role-id15520654661378671735</sec:role-id> </sec:permission> <sec:permission xmlns:sec="http://marklogic.com/xdmp/security"> sec:capabilityupdate</sec:capability> sec:role-id2950849599482623662</sec:role-id> </sec:permission> <sec:permission xmlns:sec="http://marklogic.com/xdmp/security"> sec:capabilityread</sec:capability> sec:role-id17774220447394382090</sec:role-id> </sec:permission> {"capability":"read", "roleId":"8487823278258687528"}' Stack Trace At line 1 column 0: In xdmp:eval("xdmp:document-load("C:\Users\admin-rp\Documents\myFile.xml&...", (), <options xmlns="xdmp:eval"><database>6682922067126681120</database>...</options>)

  1. xdmp:document-load("C:\Users\admin-rp\Documents\myFile.xml",
  2. map:map() => map:with("uri", "/documents/myFiles.xml")
  3. => map:with("permissions",

==================================================

Can anyone please look and suggest me what exactly I am missing in both cases?


Solution

  • In the first instance, with the XDMP-PLACEKEYSLOCKING error, you are telling it which forest to insert the document, rather than allowing the database to decide based upon the assignment policy which forest the document should live in.

    https://docs.marklogic.com/guide/ingestion/xquery#id_24146

    In order to load a document into a forest by explicitly specifying a forest key, the forest must exist and be attached to the database into which you are loading. Attempting to load a document into a forest that does not belong to the context database will throw an exception. Additionally, the locking parameter must be set to strict on the database configuration, otherwise an XDMP-PLACEKEYSLOCKING exception is thrown.

    If you have the locking set to fast and attempt to assign the document to a particular forest, you will get that error. You would need to set locking to strict, in order to ensure that the nodes in the cluster get the timestamps distributed as the transaction completes and there is no chance for another competing transaction to have placed a doc with that same URI in a different forest. https://help.marklogic.com/knowledgebase/article/View/243/0/fast-vs-strict-locking

    In your second attempt, the XDMP-INVOPTVAL error is telling you that the option permissions has an invalid value.

    Looking at the two items in the sequence for the permission, the permissions returned from:

    xdmp:default-permissions("objects")
    

    are in the format of "elements", not "objects". It seems that you were looking to specify the format as "objects" and not specify a URI. However, if you don't have something for the first parameter, it will assume that you were trying to obtain the default permissions for the URI of "objects" (first parameter).

    Use an empty sequence for the first parameter, so that it returns the default permissions for that user:

    xdmp:default-permissions((), "objects")
    

    That is documented in the second example for xdmp:default-permissions()