clear database of marklogic

43 Views Asked by At

Is there an API which can be called to clear the database of MarkLogic?

I have been using the "clear" button present in the admin UI page but I want to use this feature in a script. I have tried creating an xquery module and calling it via eval, while using the below query:

 for $forest-id in xdmp:database-forests(xdmp:database())
 return xdmp:forest-clear($forest-id) 

Still I would want to know if there is an API present for the same.

1

There are 1 best solutions below

2
On BEST ANSWER

Yes, What You are trying to do is available via the management API: [POST]/manage/v2/databases/[id-or-name]

There is a difference, though: In this case, You need to name the database for which You want to delete rather than it be set via context (database for app server hit).

It goes without saying that this is a very sharp tool, so use with care and caution. However, MarkLogic tries to take this into account in that the user needs some very granular permissions as stated in the docs.

The payload You would want can be seen in the samples:

JSON

 {
   "operation": "clear-database"
 }
 

XML

<clear-database-operation xmlns="http://marklogic.com/manage">
  <operation>clear-database</operation>
</clear-database-operation>