Ratingsdisplay doesn't update the count of deleted reviews

I deleted one review in the dataset but my Ratingsdisplay doesn't update the count of deleted reviews

Here is the code review RatingsDisplay:
async function loadStatistics() {
    // Get the statistics data based on the current product's ID.
    const stats = await wixData.get('review-stats', product._id); 
    // If statistics data for the product was found:
    if (stats) { 
        // Compute the product's average rating by dividing the total points by the number of ratings.
        let avgRating = (Math.round(stats.rating * 10 / stats.count) / 10); 
        // Compute the percentage of reviewers that recommend the product.
        let percentRecommended = Math.round(stats.recommended / stats.count * 100); 
        // Get the ratings element.
        let ratings = $w('#ratingsDisplay');
        // Set the ratings element's average rating to the value calculated above. 
        ratings.rating = avgRating;
        // Set the ratings element's number of ratings to the count value from the statistics data.
        ratings.numRatings = stats.count;
        // Set the text for the recommended percentage element.
        $w('#recoPercent').text = `${percentRecommended} % would recommend`; 
        // Show the ratings element.
    // If there is no statistics data for the product:
    } else {
        // Set the text for the recommended percentage element to reflect the fact that there are no reviews.
        $w('#recoPercent').text = 'There are no reviews yet'; 
    // Show the recommended percentage element only after it is populated to avoid flickering.  

Hi there,

You’re populating the rating element with a query, so there’s no way for the element to tell if and when you delete a review.

Upon deleting a review, you need to rerun the code that populates the rating element, it’s recommended that you wrap it inside its own function so you can just call it whenever you need it, instead of copying the code.

Can you help me, what do i need to do to fix it?

@medayskincare You should use the dataset’s remove( ) function to delete the item, then call your loadStatistics function again.

@ahmadnasriya when running remove() statement, will the old deleted item be updated?

@medayskincare how can a deleted item get updated? :thinking:

@ahmadnasriya I mean I should use remove() statement to remove items instead of deleting directly in datasets, right?