Front-end collection query works on preview but not on live site despite syncing.

The “site content” collection I’m querying from the site code (front-end) of a members-only page can be queried perfectly in the page preview but the same queries fail on the live site. This is despite me syncing the sandbox of the collection to live multiple times.

Note: All pricing plans are free while site is under construction and testing, so please go ahead and test the site. The developer’s console logs all errors.

Thanks a lot for helping!

Site link : psquareinternational.com
I have multiple pages having the same issue: psquareinternational.com /m-1 psquareinternational.com /m-3 are two of them. Others are M-2, M-4, M-5 & M-6.

My code:

The bolded line in my code shows which error I keep getting. The error-message I get is just “Error”. I am making online tests for students and I query every question one-at-a-time in the loop I made for grading answers. In the preview, all queries work. In the live site, some do and some don’t. The failed ones are different each time.

This is the code for page M-1.


import wixData from 'wix-data';
import wixWindow from 'wix-window';
import {session} from 'wix-storage';
import wixLocation from 'wix-location';
import wixUsers from 'wix-users';

let scored=0 ;

$w.onReady(function () {

 // CLOCK TIMER CODE
 if ( wixWindow.rendering.env === 'browser' || wixWindow.viewMode === 'Preview' ) {

 let datetime = new Date().getTime();

 let countdown = setInterval(function () {
 let now = new Date().getTime();
 let timepassed = now-datetime;
 let timeleft = 180000-timepassed;
 let minutes = Math.floor((timeleft % (1000 * 60 * 60)) / (1000 * 60));
 let seconds = Math.floor((timeleft % (1000 * 60)) / 1000);

            $w("#minutes").text = "" + minutes;
            $w("#seconds").text = "" + seconds;

 if (timeleft > 0) {
            } else {
                clearInterval(countdown);
                $w("#minutes").text ="0.";
                $w("#seconds").text ="0.";
                calculateScore();
            }
        }, 1000);
    }
});

export function button1_click(event) {
    calculateScore();
}

function calculateScore () {
 if (scored===1) return;
    scored=1;
 let totalquestions = 50 ;
 var score = 0 , count = 0 ;

    $w("#repeater1").forEachItem(($w,itemdata,index) => {
 var myanswer = $w("#input1").value;
        myanswer = Number(myanswer);

 var correct = null ;

 // Set sno = the question number as a 2-digit string, e.g. "01" or "33".
 var sno = index+1;
 if(sno<10) sno="0"+sno; else sno=""+sno;

        wixData.query("Sums").eq("q","Q" + sno)    
            .find()
            .then((results) => {    // THIS QUERY FAILS
 if (results.items.length > 0) {
 var item = results.items[0];

                    correct = item.sum ;
 if ( myanswer === correct ) score++;
                    count++;
                    console.log("Q"+(index+1)+" is "+myanswer+" & should be "+correct+" so you score : "+score+" &scored-qn-count:"+count);
 if(count===totalquestions) { 

                        console.log(" your score is : "+score+"/"+totalquestions);
                        $w("#text19").text = "Congratulations, you scored "+score+" out of "+totalquestions+" !";
                        $w("#text19").show();

 let toSave = {
 "type": "Typed",
 "score": score,
                        };

                        wixData.save("Scores", toSave)
                        .then( (resultss) => {
                            session.setItem("score", score);
                            session.setItem("type", "Typed");
                            wixLocation.to("/result-page");
                        } )
                        .catch( (error) => {
                        console.log("error in saving typed test score to db : "+error);
                        } );

                    } 
                } else {
                    console.log("did not find in db - "+"Q" + sno);
                }
            }).catch((error)=>{
                console.log("did not find in db - "+"Q" + sno+" because of error : "+error);    // THIS IS THE ERROR I KEEP GETTING
            });
    });
}

Possible issues:

  • The positioning of the query in the code. Although it is only called after page-load.
  • Collection and dataset permissions.
  • Unsuccessful syncing - although my live collection contains the elements whose queries are failing.