From 26fe4669ebff9e4d1a03a0515f1789d302d30c1a Mon Sep 17 00:00:00 2001 From: Old Grandpa Date: Sun, 21 Jul 2019 14:40:37 +0300 Subject: [PATCH] Documentation for ParseQuery.withCount See: https://github.com/parse-community/Parse-SDK-JS/issues/865 https://github.com/parse-community/Parse-SDK-JS/pull/868 --- _includes/js/queries.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/_includes/js/queries.md b/_includes/js/queries.md index 2d8da30f7..5caf1776a 100644 --- a/_includes/js/queries.md +++ b/_includes/js/queries.md @@ -57,6 +57,25 @@ You can skip the first results by setting `skip`. In the old Parse hosted backen query.skip(10); // skip the first 10 results ``` +If you want to know the total number of rows in table satisfying your query, for e.g. pagination purposes - you can use `withCount` (`false` by default). **Note** Enabling this flag will change the structure of response, see example below. + +Let's say you have 200 rows in `GameScore` table: + +```javascript +const GameScore = Parse.Object.extend("GameScore"); +const query = new Parse.Query(GameScore); + +query.limit(25); + +const results = await query.find(); // [ GameScore, GameScore, ...] + +// to include count: +query.withCount(true); +const response = await query.find(); // { results: [ GameScore, ... ], count: 200 } +``` + +> If you only want to get the count without objects - use [Counting Objects](#counting-objects). + For sortable types like numbers and strings, you can control the order in which results are returned: ```javascript