I have a set of user names, who are to be removed from the marklogic database. Some of the users from the list may or may not exist in the database. I tried using below script but it fails when there is no user found. How to make the script run without stopping when a user is not found i.e. to go ahead with the removal of the next user rather than erroring out and stopping the script execution. Please help.
xquery version "1.0-ml";
import module namespace sec = "http://marklogic.com/xdmp/security" at "/MarkLogic/security.xqy";
declare variable $USERS := ("user1","user2","user3");
for $user in $USERS
return $user||'-'||fn:empty((sec:remove-user($user)));
Below is the error
[1.0-ml] SEC-USERDNE: (err:FOER0000) User does not exist: sec:user-name = user1
Stack Trace
In /MarkLogic/security.xqy on line 3612
In get-element("http://marklogic.com/xdmp/security", "sec:user", "sec:user-name", "user1", "SEC-USERDNE")
$col := "http://marklogic.com/xdmp/security"
$elem := "sec:user"
$filter := "sec:user-name"
$value := "user1"
$function-error := "SEC-USERDNE"
$filterValue := <sec:user-name xmlns:sec="http://marklogic.com/xdmp/security">user1</sec:user-name>
$outElem := ()