Created
September 16, 2015 20:24
-
-
Save dmcassel/ad90d751b227a20d861e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Evaluate standard XPath against JSON (or XML or both). JSON properties operate similar to unnamespaced | |
* XML elements. | |
*/ | |
var total = 0, count = 0; | |
// XPath is a subset of XQuery. Evaluate it. | |
var resultIter = | |
xdmp.xqueryEval('/node()[some $name in friends/name satisfies starts-with(upper-case($name), "N") or eyeColor = "blue"]'); | |
for (var result of resultIter) { | |
total += result.age; | |
count++; | |
}; | |
"Average age of people who have blue eyes or are friends with others whose names start with \"N\": " + (total/count); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment