How to count the numbers of your database (display on site)

For example I have 20 babysitters in New York and I want to count the numbers (20) and put it on my site so everyone can see there are 20 babysitters in new york

Please help me!

Hi,
Basically you need to use query and count the number of results you get. This should be modified to your needs( for example if you want to get the results with “location” field that equals to “new york”, use “.eq”)

Good luck :slight_smile:

Do you have a full writtten code? :slight_smile:

Hi,
The code should look like this (modify it to match your needs):

import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .eq("status", "active")
  .count()
  .then( (num) => {
    let numberOfItems = num;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

for more information - https://www.wix.com/code/reference/wix-data.WixDataQuery.html#count

Good luck :slight_smile:

Yes i know but i want text! How can i connect this code with the text that shows how many

// For full API documentation, including code examples, visit http://wix.to/94BuAAs
import wixData from ‘wix-data’;
// …

$w.onReady( function () {
//TODO: write your page related code here…

wixData.query(“VehicleListDB”)
.eq(“vehicleStatus”, “Available”)
.find()
.then( (results) => {
if (results.items.length > 0) {
let items = results.items;
let firstItem = items[0];
let totalCount = results.totalCount;
let pageSize = results.pageSize;
let currentPage = results.currentPage;
let totalPages = results.totalPages;
let hasNext = results.hasNext();
let hasPrev = results.hasPrev();
let length = results.length;
let query = results.query;

  $w("#TextCount").text = totalCount.toString();      
}  **else**  { 

// handle case where no matching items found
}
} )
. catch ( (error) => {
let errorMsg = error.message;
let code = error.code;
} );

import wixData from ‘wix-data’; ----> Allow usage of wixdata API
$w(" #TextCount ").text = totalCount.toString(); ----> set textbox id property to TextCount


you can do this by right click + view properties (only available on Developers Mode: On)

@pranavasagarvarthi Please do not bump year old threads. Follow our community guidelines on making a post in the forum.