Rajasekar Rajasekar (Customer) asked a question.

Implement automatic document versioning with properties using XQuery

We need an XQuery solution in MarkLogic that automatically creates a version whenever a document is inserted or updated using its document URI (

docuri

).

The solution should support TXT, JSON, and XML files. Each version must capture the document content and its properties, including custom properties such as

username

.

Requirements:

  • On insertion, create the document and its initial version.
  • On each update using the same
  • docuri
  • , create a new version.
  • Copy the properties associated with that insert or update into the corresponding version.
  • Preserve existing versions and their original properties.
  • Identify each version by its original document URI and a unique version identifier.
  • Ensure the document write and version creation succeed or fail together.

Example:

Insert

/documents/sample.xml

with

username = "user1"

 

→ version 1 contains the content and

username = "user1"

.

Update the same document with new content and

username = "user2"

 

→ version 2 contains the updated content and

username = "user2"

. Version 1 remains unchanged.

Request:

Please provide or implement the XQuery functions and any required configuration to support this behavior automatically.