Loading TOC...

fn:collection

fn:collection(
   [$uri as xs:string*]
) as document-node()*

Summary

Returns all of the documents that belong to the specified collection(s).

Parameters
$uri The URI of the collection to retrieve. If you omit this parameter, returns all of the documents in the database. If you specify a list of URIs, returns all of the documents in all of the collections at the URIs specified in the list.

Example

fn:collection("mycollection")[1]
=> returns the first document in the "mycollection" collection

Comments

  • Is there a way to find content search for particular collection???
    • <a href="http://api.marklogic.com/cts:collection-query">cts:collection-query()</a>
      • Thanks David for your response.Also, Search content excluding certain collection. Is there a way for doing this?
  • What if you want to show only documents associated with certain collections?
    • Pass in the names of the collections you want documents from -- these will work as an and-query: <code>fn:collection(("collection1", "collection2"))</code>. If you want documents from any of a few collections, use a search and collection-query: <code>cts:search(fn:doc(), cts:or-query((cts:collection-query("collection1"), cts:collection-query("collection2"))))</code>
      • Thanks for your response David. From my tests fn:collection operates using "or", so I will be using cts:and-query to narrow my search to only documents which include all specified collections. I ended up constructing a string which I pass to xdmp:eval (see below) let $query :=fn:concat("cts:and-query((cts:collection-query('",fn:string-join($colls,"'),cts:collection-query('"),"')))")
        • You can simplify that code: <code>let $query :=cts:and-query((cts:collection-query($colls)))</code> (if you really need it to be a string, you can pass it to <code>xdmp:quote()</code>.
Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy