Skip to content

Commit 4973012

Browse files
BufferUnderflowerdplewis
authored andcommitted
Add documentation for [JS-SDK] ParseQuery.withCount (#644)
* Documentation for ParseQuery.withCount See: parse-community/Parse-SDK-JS#865 parse-community/Parse-SDK-JS#868 * added disclaimer * remove extra line breaks * Update _includes/js/queries.md Co-Authored-By: Tom Fox <[email protected]> * Update _includes/js/queries.md Co-Authored-By: Tom Fox <[email protected]> * simpler
1 parent 02af339 commit 4973012

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

_includes/js/queries.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@ You can skip the first results by setting `skip`. In the old Parse hosted backen
5757
query.skip(10); // skip the first 10 results
5858
```
5959

60+
If you want to know the total number of rows in a table satisfying your query, for e.g. pagination purposes - you can use `withCount`.
61+
62+
**Note:** Enabling this flag will change the structure of response, see the example below.
63+
64+
Let's say you have 200 rows in a table called `GameScore`:
65+
66+
```javascript
67+
const GameScore = Parse.Object.extend("GameScore");
68+
const query = new Parse.Query(GameScore);
69+
70+
query.limit(25);
71+
72+
const results = await query.find(); // [ GameScore, GameScore, ...]
73+
74+
// to include count:
75+
query.withCount();
76+
const response = await query.find(); // { results: [ GameScore, ... ], count: 200 }
77+
```
78+
⚠️ Сount operations can be slow and expensive.
79+
> If you only want to get the count without objects - use [Counting Objects](#counting-objects).
80+
6081
For sortable types like numbers and strings, you can control the order in which results are returned:
6182

6283
```javascript

0 commit comments

Comments
 (0)