我想檢索集合中的文檔,該集合滿足給定元素沒有特定的子元素。例如,從下面的兩個「文檔」中,我想選擇文檔2,因爲它具有元素子元素,但是文檔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
該查詢返回正是那些有子元素的文檔。
什麼給?
這真的很奇怪。如果你使用`count($ item // child)`,你會得到什麼輸出 - 是否有0? – 2009-07-31 08:47:50