Search code examples
marklogicmarklogic-7

Find number of documents in a collection in Marklogic7 using Marklogic Rest API


I am using Marklogic 7 Rest API and I want to find out the number of documents in any collection in my Marklogic database. How can this be achieved?


Solution

  • You can POST a query on the collection with a page length of 1:

    {"query": { "queries": [{ "collection-query": { "uri": ["YOUR_COLLECTION"] } }] }}

    http://docs.marklogic.com/REST/POST/v1/search

    http://docs.marklogic.com/guide/search-dev/structured-query#id_76890

    The total property in the search response will indicate the number of documents in the collection.