Does anyone know how to dynamically calculate and post on web page total count of registered members? Want to post on home page

Hi there,

To do that, you need a backend function to bypass the private members collection’s permissions , once you read the tutorial in the example and feel that you’re comfortable with it, create this function on the backend, then call it from your home page.

// Backend web module (.jsw)

const members_col = 'Members/PrivateMembersData';
const options = { suppressAuth: true }

export function getMembersNum() {
    return wixData.query(members_col).find(options).then((x) => {
        return x.totalCount;
    }).catch(err => {
        return Promise.reject(err);

Hope this helps~!

You can also use the query count() function instead of find().

Hi Yisrael, Sorry for the late response, but ‘thank you’ very much for your information and replying so quickly to provide your help. I will try what has been presented on this forum.

Hi Ahmad, Sorry for the late response, but ‘thank you’ very much for your detailed response. I definitely will try what has been presented on this forum in the next couple of days and will report my results. Thanks again!

Hi Ahmad, I finally got the code to work but noticing a problem… When I’m in the editor and do ‘Preview’ I get the correct number for my "Member/PrivateMemberData’ count to appear in the Console Log and on my Home page. However, when I log in as a user, any of the 4 test users that I have, in the Published version, my count is ALWAYS ‘1,’ and sometimes no number at all appears. Can you tell me why is this? I used the getMembers Num function as you had in the code you provided. Please advise. My exact code is below:

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 () { // Write your JavaScript here getMembersNum ();