Count Query Results
-
The following options are available to count query results:
Count
-
Call
count
to get the number of items in the query results. -
Method
longCount
, which is also available, produces exactly the same results ascount
.
It is only included to be consistent with the .NET client.
const numberOfOrders = await session
.query({ collection: "Orders" })
.whereEquals("ShipTo.Country", "UK")
// Call 'count' to get the number of results
.count();
// The query returns the NUMBER of orders shipped to UK
from "Orders"
where ShipTo.Country == "UK" limit 0, 0
// The RQL generated will trigger query execution
// however, no documents are returned (limit is set 0)
Get count from query stats
-
When executing a query, you can retrieve the query statistics, which include the total number of results.
-
The total number of results is available in the
totalResults
property of theQueryStatistics
object.
Learn more in Get Query Statistics.