我想检索集合中满足给定元素没有特定子元素的文档。例如,从下面的两个“文档”中,我想选择 doc 2,因为它有元素 child,但 doc 1,因为它没有。
文件 1:
<doc>
<element>
<child/>
</element>
</doc>
文件 2:
<doc>
<element>
<other-child/>
</element>
</doc>
我试过这样做:
for $item in collection('/db/collection')
where not($item//child)
return $item
但是,由于某种原因,这不起作用。我也尝试了各种组合exists
,序列函数等,但无法得到我想要的结果。
澄清一下,not($item//child)
测试似乎没有做我认为它会做的事情。上面的查询返回我集合中的每个文档,不管它是否有元素。然而,逆向有效:
for $item in collection('/db/collection')
where $item//child
return $item
此查询准确返回具有子元素的那些文档。
是什么赋予了?