I want to retrieve the documents in a collection which satisfy that a given element does not have a specific child element. For example, from the two "documents" below, I want to select doc 2, since it has the element child, but doc 1, since it does not.
Doc 1:
<doc>
<element>
<child/>
</element>
</doc>
Doc2:
<doc>
<element>
<other-child/>
</element>
</doc>
I tried doing this:
for $item in collection('/db/collection')
where not($item//child)
return $item
However, this does not work for some reason. I also tried various combinations of exists
, sequence functions etc, but couldn't get the result I want.
To clarify, the not($item//child)
test does not seem to do what I think it'd do. The above query returns every document in my collection, wether it has the element or not.
The inverse works, however:
for $item in collection('/db/collection')
where $item//child
return $item
This query returns exactly those documents which have the child element.
What gives?