Review statistics updated fail


I used a Yoav tutorial to create a review system that its not working perfectly.

I have 2 problems:

1- The Review stats database is not being uploaded (IDK why).
2- The users can submit just 1 review, after that all the reviews are upload but not updated to the different databases. The lightbox is also not closing at the end.


What should I do?

Thank you very much!

PS: My code on the light box (the main problem for updating statistics):

import wixWindow from 'wix-window';
import wixData from 'wix-data';

let companyId;
let rated = false;
let reviewRating;

$w.onReady(function () {
    companyId = wixWindow.lightbox.getContext().companyId;

    $w('#SubmitReviews').onBeforeSave(() => {
 if (!rated) {
 return Promise.reject();
            rating: reviewRating || 0,
            recommends: $w('#radioGroup1').value
    $w('#SubmitReviews').onAfterSave(async () => {
 await updateStatistics($w('#radioGroup1').value);

const blueStars = ["starBlue1", "starBlue2", "starBlue3", "starBlue4", "starBlue5"];
const grayStars = ["starGray1", "starGray2", "starGray3", "starGray4", "starGray5"];

function initStars() {
 for (let i = 0; i < grayStars.length; i++) {
 const numberOfStar = i+1;
 const grayStar = $w(`#starGray${numberOfStar}`)
 const blueStar = $w(`#starBlue${numberOfStar}`)

        grayStar.onMouseIn((event) => {
        blueStar.onMouseIn((event) => {
            rated = true;
            reviewRating = numberOfStar;

function fillStars(numberOfStars) {
 for (var i = 0; i < blueStars.length; i++) {
 const numberOfStar = i+1;
 let star = $w('#'+blueStars[i]);
 if (numberOfStar <= numberOfStars) {
        } else {

async function updateStatistics(isRecommended) {
 let stats = await wixData.get('ReviewStats', companyId);
 if (stats) {
        stats.rating += reviewRating;
        stats.count += 1;
        stats.recommended += isRecommended?1:0
 return wixData.update('ReviewStats', stats)
    stats = {
        _id: companyId,
        rating: reviewRating,
        count: 1,
        recommended: isRecommended?1:0
 return wixData.insert('ReviewStats', stats)

I need help :frowning:

You can use the example of it here . If you copy the code from the example, please make sure that the IDs, the names of the collections and the collections permissions are the same as the example.

Good luck!

Hi Tal, the example there isn’t working for me, i’ve edited every field and dataset to match mine but no luck! The average rating isn’t upadting in my review-stats dataset. Nothing. So i must be missing something. The reviews are updated perfectly.

I used the code from here as an example:

I’ve been trying for the last week, but i can’t see any errors.

1 Like