wixData.insert only works in Preview


I’m trying to store the text that users search for on my site and am using the below code to write the text to a collection called Searches.

This code works perfectly in Preview, but when published doesn’t write anything to the collection.

Sandbox Mode is Off.

Can anyone suggest why it doesn’t work please ?

Thanks in advance

function storeSearches () {
( async () => {
const item = { SearchText : $w ( “#searchbar” ). value };
const result = await wixData . insert ( ‘Searches’ , item );

Hi there …

Please check the database permissions, in preview, you have the " Admin " privilege, which allows you to perform any action on the database, however, if you’re on the live site, the current member’s permissions will apply.

You can bypass the permissions on the backend, but I assume you’re on frontend.


Aaaah, that makes a lot of sense. Thank you. Issue solved.

You’re welcome, happy to help :blush: