I’m trying to dynamically capture the count of records from my Members/PrivateMembersData collection table and post on my home page. I have the following page code (see below). But when I execute the code in the editor by previewing the page, I get the correct count in the console log and posted on the home page. However, when I run the published version of my website as one of the registered site members, the count on the Home page always posts as ‘1’ and not correctly as ‘4,’ since there are 4 records in the collection table.
-
Can someone help me understand this difference in behavior?
-
Can you help me with a fix so that the correct count appears by any website user on the Home page when the site is published?
-
I only have code writing in the page…do I need any backend js code?
Thank you in advance.
MY PAGE CODE:
import wixData from ‘wix-data’ ;
const members_col = ‘Members/PrivateMembersData’ ;
const options = { suppressAuth : true };
export function getMembersNUM () {
return wixData . query ( members_col ). find ( options ). then (( x ) => {
let allResults = x . totalCount ;
console . log ( allResults ); //this is the number of results
$w ( “#text164” ). text = "Registered Connect Members: " + allResults ;
return allResults ;
}). catch ( err => {
return Promise . reject ( err );
})
}
$w . onReady ( function () {
getMembersNUM ();
});