2

My requirement is get the count of total documents available in database.

cts.estimate(
  cts.trueQuery()
)

When I execute above query it is returning 1283265 document count but when I explore database from qconsole then document count is 1283262 so I am not sure about this document count mismatch.

Any help is appreciated.

DevNinja
  • 1,459
  • 7
  • 10
  • And you are sure that content isn't changing (docs being added/removed)? Is it consistently different by the same amount of docs? – Mads Hansen May 01 '21 at 15:30
  • Yes @Mads Hansen no document is getting added or removed. – DevNinja May 02 '21 at 00:31
  • @MadsHansen Update - I tried using search:estimate(cts:true-query()) and it is returning same document count as shown in qconsole by exploring. – DevNinja May 02 '21 at 01:06

1 Answers1

2

Is it possible that you have some URIs in the database that do not have documents?

The code backing the Query Console explore button only reports the estimated number of documents:

let $total-doc := xdmp:estimate(doc())

The default behavior for cts.estimate() is to search for any fragment.

Only one of "any", "document", "properties", or "locks" may be specified in the options parameter. If none of "any", "document", "properties", or "locks" are specified and there is a $query parameter, then the default is "document". If there is no $query parameter then the default is "any".

Run this query and verify what numbers are reported when explicit options are specified for estimates:

const estimate_default = cts.estimate(cts.trueQuery());
const estimate_any = cts.estimate(cts.trueQuery(), ["any"]);
const estimate_documents = cts.estimate(cts.trueQuery(), ["document"]);
const estimate_properties = cts.estimate(cts.trueQuery(), ["properties"]);
const estimate_locks = cts.estimate(cts.trueQuery(), ["locks"]);

[estimate_default, estimate_any, estimate_documents, estimate_properties, estimate_locks];

I would suspect that the difference in numbers is because of some URIs that do not have documents. It is possible, for instance, to have properties fragments for a URI and not have a document.

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147