Tables populated by wixData.query are not showing expected behaviour on published site, but do in Preview

Hello,

I’m attempting to populate two tables using corresponding wixData.query functions on a collection (see below) containing ~3200 items, where multiple items have the same values for the first property, constituency_name:

My queries are as follows, where resultArray[0] and resultArray[1] are strings referring to two different constituencies:

wixData.query("TableData")
.descending("votes")
.eq("constituency_name", resultArray[0])
.find()
.then((homeData) => {
    console.log(homeData);
    $w('#homeTable').rows = homeData.items;
    })
 .catch(error => {
    console.log(error);
    });

wixData.query("TableData")
.descending("votes")
.eq("constituency_name", resultArray[1])
.find()
.then((termtimeData) => {
    console.log(termtimeData);
    $w('#termtimeTable').rows = termtimeData.items;
    })
.catch(error => {
    console.log(error);
    });

In Preview, the tables display the queries as expected:

But on my published site, my tables are populated with queries and lose their ordering:

I am completely stumped. Any help is greatly appreciated.

Site URL: https://www.mystudentvote.org.uk

Are you sure you didn’t connect the table to a dataset via the editor and you only have these queries?

@jonatandor35 Certain, these tables are not connected to any datasets.

@ryanmorgan and do the console.log’s work as expected?

@jonatandor35 In Preview, the console.log’s show the expected wixDataQueryResult items and this matches what is passed to the tables - an array.length of 5 and an array.length of 4.

On my published site, the logged wixDataQueryResult’s show the unexpected behaviour like the tables, tested in Chrome developer console - two arrays of array.length 15, which is really weird considering the expected item array lengths are different, and no limit is set in the query.

Any chance I could get your thoughts please? @yisrael-wix

@ryanmorgan I have no idea. It’s been a while since Yisrael posted any comment. Maybe you’d like to ask other forum mods.

@jonatandor35 OK, thanks for letting me know J. D. I’ll give it another day and see if it gets picked up on the front page of the Community Discussion.

Have you check your collection permission? In editor code is execute as admin so It would works everytime. But on live you might be logged as visitor and might not have the permission to change/view data

If it was a permissions issue, wouldn’t the tables be empty on the published site because the query wouldn’t run?

Anyway, I’ve added suppressAuth to find and it hasn’t resolved the issue. This is a nightmare!

Edit: this wixData.query is on the frontend (page code) - might that be the problem?

@ryanmorgan you cannot use suppressAuth in the front end but you don’t need to.
Just go to your collection and set the permissions.
Anyway, I think you’re right and it should be empty if the permissions are wrong.

@jonatandor35 This is really weird and frustrating. I have several other wixData.query functions on my site all working fine, it’s just these two supplying items to the tables refuse to behave! Where/who else could I turn to? Thanks for your ongoing help BTW.

@ryanmorgan Try to sync the collection sandbox with your live site. Maybe it’ll help somehow.

@jonatandor35 I’ve done that!

I’ve found the issue. It’s not in the wixData.query itself but in my collections. When I’ve been syncing sandbox data to live data, it’s been duplicating it, so my TableData collection has three copies of every item! Why did this happen?

No idea. Really strange.