marklogicmarklogic-9

Clear collections is not working in Java API


We are using MarkLogic v10 and Java API v4.1.0. Our requirement is to clear collections from the specific document,

we are using below code snippet to clear all the collections,

XMLDocumentManager xmlDocumentManager = client.newXMLDocumentManager();

DocumentMetadataHandle metadataHandle = new DocumentMetadataHandle();
xmlDocumentManager.readMetadata("/test/inventory", metadataHandle);

DOMHandle domHandle = new DOMHandle();
xmlDocumentManager.read("/test/inventory", domHandle);

metadataHandle.getCollections().clear();
xmlDocumentManager.write("/test/inventory", metadataHandle, domHandle);

After running the above snippet, it should remove all the collections from the document but it is not happening.

Please help me to make this work.


Solution

  • Copying the resolution from the bug in case it's useful for others.

    Clear collections only clears locally for the in-memory DocumentMetadataHandle in the Java API client of the REST API.

    The behavior of the REST API invoked by the Java API depends on the configuration of the update policy of the REST API server:

    Changing the update policy to OVERWRITE_METADATA should yield the expected behavior.

    Here's the Java API code for making that change:

        ServerConfigurationManager configMgr = client.newServerConfigManager();
        configMgr.readConfiguration();
        configMgr.setUpdatePolicy(ServerConfigurationManager.UpdatePolicy.OVERWRITE_METADATA);
        configMgr.writeConfiguration();
    

    Note that

    Thanks to Shivling for digging into the issue.