我有一组用户名,他们将从 marklogic 数据库中删除。列表中的某些用户可能存在也可能不存在于数据库中。我尝试使用以下脚本,但在找不到用户时失败。如何在未找到用户时让脚本运行而不停止,即继续删除下一个用户,而不是出错并停止脚本执行。请帮忙。
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)));
Run Code Online (Sandbox Code Playgroud)
下面是错误
[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 := ()
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以添加一个where子句来检查用户是否存在。所以,像这样
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
where sec:user-exists($user)
return $user||'-'||fn:empty((sec:remove-user($user)));
Run Code Online (Sandbox Code Playgroud)
如果您希望它根据用户是否被实际删除来打印 true 或 false,您可以将该检查if作为return替代的一部分。
| 归档时间: |
|
| 查看次数: |
36 次 |
| 最近记录: |