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

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.

Comments

The commenting feature on this page is enabled by a third party. Comments posted to this page are publicly visible.
  • Is there any way to Retrieve Document uris from specific Collection ?
    • You'll want to get familiar with the cts:uris and cts:collection-query functions: http://docs.marklogic.com/cts:uris http://docs.marklogic.com/cts:collection-query For example, this would return the URIs of the documents in a collection called "my-collection": cts:uris((),(), cts:collection-query("my-collection"))
  • 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>.