Loading TOC...

fn.collection

fn.collection(
   [$uri as String[]]
) as Sequence

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.head(fn.collection("mycollection"));
=> returns the first document in the "mycollection" collection

Example

const res = [];
const d = fn.subsequence(fn.collection("my-collection"), 1, 2);
for (const x of d) {
res.push(x); };
res;

=> The first 2 documents in the Sequence containing the collection

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

Comments

  • Hi I have used this method but i'm getting error like u can in the attached screen shot https://uploads.disquscdn.com/images/83f53260ed9b1676188a720c5044f3cf41c96cdb6ca116f7c5b1446865ff5a75.png in parameters what should in need to pass? my requirement is i need to fetch the list of all docs in "DEMO" database is that possible with this function? can some one suggest me the right way to do it even rest API it is fine. Thanks in advance sai kumar
    • You are trying to execute JavaScript as XQuery. Change the query type to JavaScript and remove the first line, or refer to the documentation for the XQuery version of this function (fn:collection).