How To Return the Document Excluding One of The Child Nodes


A sample document would be:

Joe A 234 J st JJJJ 123456789 9099808990

How do I return the entire Customer document, except for a Secret child node, in the most efficient way?


Efficient is something strange, without the real data it is hard to challenge… You could use XSLT to transform the document and remove the element. For larger replies that is what I would go for.

for $i in collection(“yourcollection”)
where $i/Customer/Name=“Joe A”
return {$i/Customer/Name/text()}…

Just return everything this way but the Secret.

Depends on the size of your application and the number of documents, I would expect this to be fast. But efficient?? Depends on what variables and benchmarks you are using. Transforming in a query is no fun, but XSLT isn’t either. Processing time I don’t know, you’d need to test it.

Or you could keep the “secret” document parts as a separate document type?

How about

for $i in collection("yourcollection")/Customer
where $i/Name="Joe A" 
return ($i/* except $i/Secret)