Skip to content

Commit

Permalink
Merge pull request #1681 from Danielle9897/RDoc-2475-NodeJs-countResults
Browse files Browse the repository at this point in the history
RDoc-2475 Client API > Session > Querying > Count query results
  • Loading branch information
ppekrol authored Aug 3, 2023
2 parents 01b7199 + 1630ba8 commit 6f1282d
Show file tree
Hide file tree
Showing 22 changed files with 554 additions and 329 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ Stats are returned in the `DetailedDatabaseStatistics` object.
### FAQ

- [What is a Collection](../../../client-api/faq/what-is-a-collection)

### Client API

- [Get Query Statistics](../../../client-api/session/querying/how-to-get-query-statistics)
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ Detailed database stats results:
### FAQ

- [What is a Collection](../../../client-api/faq/what-is-a-collection)

### Client API

- [Get Query Statistics](../../../client-api/session/querying/how-to-get-query-statistics)
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
},
{
"Path": "how-to-count-query-results.markdown",
"Name": "How to Count Query Results",
"Name": "Count Query Results",
"DiscussionId": "77cec3b4-0001-4a30-81a7-e3182f4150bf",
"Mappings": []
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ Available custom methods and extensions:
- CmpXchg
- ContainsAll
- ContainsAny
- Count
- CountLazily
- [Count](../../../../client-api/session/querying/how-to-count-query-results)
- [CountLazily](../../../../client-api/session/querying/how-to-perform-queries-lazily#lazy-count-query)
- Distinct
- ExplainScores
- First
Expand All @@ -191,7 +191,7 @@ Available custom methods and extensions:
- InvokeAfterQueryExecuted
- InvokeAfterStreamExecuted
- [Query] [Lazily](../../../../client-api/session/querying/how-to-perform-queries-lazily)
- LongCount
- [LongCount](../../../../client-api/session/querying/how-to-count-query-results)
- MoreLikeThis
- NegateNext
- [Not](../../../../client-api/session/querying/document-query/how-to-use-not-operator)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Count Query Results

---

{NOTE: }

* The following options are available to __count query results__:

* [Count](../../../client-api/session/querying/how-to-count-query-results#count)

* [LongCount](../../../client-api/session/querying/how-to-count-query-results#longcount)

* [Get number of results from query stats](../../../client-api/session/querying/how-to-count-query-results#get-count-from-query-stats)

{NOTE/}

---

{PANEL: Count}

* When the number of resulting items is expected to be an **`Int32`** variable,
use `Count` in a synchronous session (or `CountAsync` in an async session).

* `Count` is implemented in `System.Linq`.
`CountAsync` is implemented in `Raven.Client.Documents`.

* An `OverflowException` will be thrown if the number of items exceeds **`Int32.MaxValue`**.

{NOTE: }

{CODE-TABS}
{CODE-TAB:csharp:Query count_1@ClientApi\Session\Querying\CountQueryResultsUsingLinq.cs /}
{CODE-TAB:csharp:Query_async count_2@ClientApi\Session\Querying\CountQueryResults.cs /}
{CODE-TAB:csharp:DocumentQuery count_3@ClientApi\Session\Querying\CountQueryResults.cs /}
{CODE-TAB-BLOCK:sql:RQL}
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)
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{NOTE/}

{PANEL/}

{PANEL: LongCount}

* When the number of resulting items is expected to be an **`Int64`** variable,
use `LongCount` in a synchronous session (or `LongCountAsync` in an async session).

* `LongCount` is implemented in both `Raven.Client.Documents` & `System.Linq` (use as needed).
`LongCountAsync` is implemented in `Raven.Client.Documents`.

{NOTE: }

{CODE-TABS}
{CODE-TAB:csharp:Query count_4@ClientApi\Session\Querying\CountQueryResults.cs /}
{CODE-TAB:csharp:Query_async count_5@ClientApi\Session\Querying\CountQueryResults.cs /}
{CODE-TAB:csharp:DocumentQuery count_6@ClientApi\Session\Querying\CountQueryResults.cs /}
{CODE-TAB-BLOCK:sql:RQL}
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)
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{NOTE/}

{PANEL/}

{PANEL: Get count from query stats}

* When executing a query,
you can retrieve the query statistics which include the total number of results.

* The number of results is available in the `QueryStatistics` object as:
* `TotalResults` - an Int32 value
* `LongTotalResults` - an Int64 value

* Learn more in [Get Query Statistics](../../../client-api/session/querying/how-to-get-query-statistics).

{PANEL/}

## Related Articles

### Client API

- [Query overview](../../../client-api/session/querying/how-to-query)
- [What is a Document Query](../../../client-api/session/querying/document-query/what-is-document-query)
- [Filter by Field Presence](../../../client-api/session/querying/how-to-filter-by-field)
- [Get Query Statistics](../../../client-api/session/querying/how-to-get-query-statistics)

### Querying

- [Filtering](../../../indexes/querying/filtering)
- [RQL - Raven Query Language](../../../client-api/session/querying/what-is-rql)
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Count Query Results

---

{NOTE: }

* The following options are available to __count query results__:

* [Count](../../../client-api/session/querying/how-to-count-query-results#count)

* [Get number of results from query stats](../../../client-api/session/querying/how-to-count-query-results#get-count-from-query-stats)

{NOTE/}

---

{PANEL: Count}

* Call `count` to get the number of items in the query results.

* Method `longCount`, which is also available, produces exactly the same results as `count`.
It is only included to be consistent with the .NET client.

{NOTE: }

{CODE-TABS}
{CODE-TAB:nodejs:Query count@ClientApi\Session\Querying\countQueryResults.js /}
{CODE-TAB-BLOCK:sql:RQL}
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)
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{NOTE/}

{PANEL/}

{PANEL: Get count from query stats}

* When executing a query,
you can retrieve the query statistics which include the total number of results.

* The number of results is available in the `QueryStatistics` object as:
* `totalResults`
* `longTotalResults`

* Learn more in [Get Query Statistics](../../../client-api/session/querying/how-to-get-query-statistics).

{PANEL/}

## Related Articles

### Client API

- [Query overview](../../../client-api/session/querying/how-to-query)
- [What is a Document Query](../../../client-api/session/querying/document-query/what-is-document-query)
- [Filter by Field Presence](../../../client-api/session/querying/how-to-filter-by-field)
- [Get Query Statistics](../../../client-api/session/querying/how-to-get-query-statistics)

### Querying

- [Filtering](../../../indexes/querying/filtering)
- [RQL - Raven Query Language](../../../client-api/session/querying/what-is-rql)

This file was deleted.

Loading

0 comments on commit 6f1282d

Please sign in to comment.