Marc Messéant (Customer) asked a question.

How to wipe a temporal document in test?

In my test suite, I create temporal document with my standard procedure so protected in noDelete level.

And the and of the test, in the teardown.xqy, I need to wipe the doc to start a new test with an empty database, I'm unable to do that.

I try to protect with an old date, but it's not possible and I don't find how to suppress the protection.

Is there a solution for that, I don't want to modify my code for the tests?

 

Thank for answer

 

Marc


  • David Ennis (Clever Llamas)

    Have You tried: temporal:document-wipe() ? This gets rid of all versions of the doc related to the main URI. Please look at the notes and you will see that You need a special privilege for this. You could always amp a teardown function and force the function to only work on the documents/database/collection you intend.

     

    If you want to delete only a single version of a temporal document, that takes another approach.

     

     

  • Marc Messéant (Customer)

    That's what I do, I find a solution :

    I protect the doc with a noDelete level and a duration of 0, and in the next transaction I wipe it.

    But when I try to do this on a old version of document with an .{id}., I have an exception as "is not a temporal document URI". The version file is in the temporal collection. It's ok for the latest doc.

     

    • Florent Georges (Customer)

      Hi Marc. Yes, "document wipe" is to delete what I call a "temporal stack." That is, you provide the URI of the document (the one that is used as well as a collection URI for all versions of the document,) and all versions are deleted. You cannot pass the URI of any specific version.

       

      If you want finer control, or rather full power, you can use "admin override" as explained by David.

  • David Ennis (Clever Llamas)

    OK. With great power comes great responsibility. Read below understanding that what is there represents very sharp tools that should be used with care as irreversible damage can be done by using xdmp:document-delete() and temporarily loosing all the protection for which the temporal system was designed. If you use the approach below and cause the world to end, that would be unfortunate for us all.

     

     

    General approach:

    1. allow temporal override for a user with specific privileges
    2. that user can use the xdmp:xxx functions on temporal documents (including delete)
    3. then set things back so no user can do this

     

    Don;t take the below verbatim - it may not be complete but shows the approach - I cobbled together notes from some internal tooling and docs. it may be outdated and incomplete, but gets you started. Also note that it is multiple xQuery statements separated by a semicolon. In reality, you would likely use 3x xdmp:invoke-function() calls.

     

    1. (: ============================================================================
    2. : Physically delete a document from a temporal collection
    3. :
    4. : MarkLogic normally prevents xdmp:document-delete() against a temporal
    5. : document and raises SEC-TEMPORALDOC.
    6. :
    7. : The "updates-admin-override" temporal collection option allows ordinary
    8. : non-temporal update functions, including xdmp:document-delete().
    9. :
    10. : temporal:collection-set-options:
    11. : https://docs.marklogic.com/temporal%3Acollection-set-options
    12. :
    13. : SEC-TEMPORALDOC:
    14. : https://docs.marklogic.com/guide/messages/SEC-en
    15. :
    16. : Semicolon-separated XQuery statements / transactions:
    17. : https://docs.marklogic.com/guide/app-dev/transactions
    18. :
    19. : IMPORTANT:
    20. : Run in normal AUTO-COMMIT mode. Each ";" separated main module is then
    21. : committed before the next statement executes.
    22. : ============================================================================ :)
    23.  
    24.  
    25. (: ---------------------------------------------------------------------------
    26. : TRANSACTION 1
    27. :
    28. : Enable temporal administrative override.
    29. :
    30. : Preserve all existing collection options and add
    31. : "updates-admin-override".
    32. :
    33. : If an override-priv=... option is already configured on the collection,
    34. : the executing user must possess that privilege.
    35. :
    36. : Documentation:
    37. : https://docs.marklogic.com/temporal%3Acollection-get-options
    38. : https://docs.marklogic.com/temporal%3Acollection-set-options
    39. : --------------------------------------------------------------------------- :)
    40.  
    41. xquery version "1.0-ml";
    42.  
    43. import module namespace temporal =
    44. "http://marklogic.com/xdmp/temporal"
    45. at "/MarkLogic/temporal.xqy";
    46.  
    47. declare variable $COLLECTION := "my-temporal-collection";
    48.  
    49. let $options := temporal:collection-get-options($COLLECTION)
    50.  
    51. return
    52. temporal:collection-set-options(
    53. $COLLECTION,
    54. (
    55. $options,
    56. if ($options = "updates-admin-override")
    57. then ()
    58. else "updates-admin-override"
    59. )
    60. )
    61.  
    62. ;
    63.  
    64.  
    65. (: ---------------------------------------------------------------------------
    66. : TRANSACTION 2
    67. :
    68. : The previous transaction has committed, so the temporal collection now
    69. : permits administrative override operations.
    70. :
    71. : xdmp:document-delete() is intentionally used here instead of
    72. : temporal:document-delete(). This performs the non-temporal physical
    73. : deletion we are deliberately enabling above.
    74. :
    75. : Documentation:
    76. : https://docs.marklogic.com/xdmp%3Adocument-delete
    77. :
    78. : The temporal override documentation specifically identifies
    79. : xdmp:document-delete as an operation enabled by updates-admin-override:
    80. : https://docs.marklogic.com/temporal%3Acollection-set-options
    81. : --------------------------------------------------------------------------- :)
    82.  
    83. xquery version "1.0-ml";
    84.  
    85. declare variable $URI := "/documents/example.xml";
    86.  
    87. xdmp:document-delete($URI)
    88.  
    89. ;
    90.  
    91.  
    92. (: ---------------------------------------------------------------------------
    93. : TRANSACTION 3
    94. :
    95. : Restore normal temporal protection by removing updates-admin-override.
    96. :
    97. : All other temporal collection options are retained, including things such
    98. : as override-priv, document-wipe-priv, document-protect-priv, archive
    99. : settings, etc.
    100. :
    101. : Documentation:
    102. : https://docs.marklogic.com/temporal%3Acollection-get-options
    103. : https://docs.marklogic.com/temporal%3Acollection-set-options
    104. : --------------------------------------------------------------------------- :)
    105.  
    106. xquery version "1.0-ml";
    107.  
    108. import module namespace temporal =
    109. "http://marklogic.com/xdmp/temporal"
    110. at "/MarkLogic/temporal.xqy";
    111.  
    112. declare variable $COLLECTION := "my-temporal-collection";
    113.  
    114. let $options := temporal:collection-get-options($COLLECTION)
    115.  
    116. return
    117. temporal:collection-set-options(
    118. $COLLECTION,
    119. $options[. ne "updates-admin-override"]
    120. )

     

     

     

  • Marc Messéant (Customer)

    Thank you for answer, It's at the return of too long holidays

    I modify my code to resolve a problem that as the document was deleted before, I don't see it in the latest collection anymore as open too much my loop to select document. I restrict now to the document who have the same uri as a collection and all is ok!

    The test of the message (not in temporal collection) gives me a bad direction to search.

    • Florent Georges (Customer)

      Good news. You can use "admin override" as explained by David, if ever you need to clean up version documents that would be left over from your previous logic.