Please enable JavaScript.
Coggle requires JavaScript to display documents.
XQuery (FLOWR (for, let, order by, where, return, the rule is that a FLWOR…
XQuery
FLOWR
-
-
-
-
-
- the rule is that a FLWOR needs one or more for or let subclauses, in any order
- return clause is mandatory
- order by and where are optional
The key thing to remember is that a "return" doesn't return control to the caller like in a procedural language. It's behaves more like a "do". (then it would be FLOWD, not FLOWR:))
fn
doc
- the doc() function without any arguments returns all documents in the database
-
-
count
- in normal programs count() is almost never used
-
Drilling in with XPath
:!: sometimes you don't want to fetch whole documents, just parts of them, and in those cases you can use XPath to specify what part of a document you want
-
-
-
-
xdmp
estimate
- it's named "estimate" rather than "count" because it's not always 100% accurate
-
(doc()/message)[1] - This query returns the first document in the database (order is essentially random, though it is stable and doesn't change between executions).
Pro tip: You can drop the leading doc() and you get the same result. Any rooted XPath is assumed to query across all documents.
-
The xdmp part of the function name is a namespace prefix. All functions have a namespace, similar to a package name in Java. The xdmp namespace holds some of MarkLogic's extension functions. The default namespace prefix is fn and it can usually be omitted. Technically doc() up there could be written as fn:doc() and you'd get the same result.
-