marklogic Very simple CRUD examples for XML documents Delete - Last, but not least

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!


To round out simple examples of CRUD operations, we present the following examples. Always use great care in deleting documents.

(: When we know the URI, we can delete it very easily :)
let $uri := "/stuff/mysimpledocument.xml"
return xdmp:document-delete($uri)

or simplified:


You can certainly use XPath to find the document, get the URI of it, and then delete it with something like this, but the danger is that any documents that are returned by the XPath expressions will be removed. Not always a good thing.

(: Use caution when using XPath to select target docs to delete :)
for $doc in /my-document
return xdmp:document-delete(fn:base-uri($doc))

Want to delete all documents? This will do it, but be very careful you know what database your code will execute against.

for $doc in fn:doc()
return xdmp:document-delete(fn:base-uri($doc))

Got any marklogic Question?