Loading TOC...


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


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

$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.


=> 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.


The commenting feature on this page is enabled by a third party. Comments posted to this page are publicly visible.
  • Can someone give me an idea on how to create a Top Songs like search and discovery application that would look into many collections. I have created an application but it has only one collection and the database is pretty small. Now I want to create a similar application that would look up into a very large database that has many collections.
    • When you search a database using any of the interfaces MarkLogic provides for search (JavaScript, XQuery, REST, Node.js, Java) you have the ability to constrain your search by collection(s). By default, when you run a search, you are searching all the documents in the database for which the user has a read permission on. This will be across the whole database (all collections) by default. You may constrain a search to only look in specific collections by using functions like cts.collectionQuery(): http://docs.marklogic.com/cts.collectionQuery Or if you are using higher-level search APIs you can implement a collection constraint with query options: http://docs.marklogic.com/guide/search-dev/query-options
  • 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>.