How to hide/show a website text based on a filled field in a collection

Hi,

I’m trying to hide a text in my website if a field in a collection is not filled. This is my code:

import wixData from 'wix-data';
$w.onReady(function () {
  //call to the collection named "Noir"
  wixData.query("#Noir")
    .find()
    .then(results => {
      //Verify if the field "account" is filled or not
      if (results.items.length > 0 && results.items[0].account) {
        //Show the text
        $w("#text40").show();
      } else {
        //Hide the text
        $w("#text40").hide();
      }
    })
    .catch(error => {
      console.error(error);
    });
});

The console give me this error but I have te collection and I verify several times the name ID and all.
Error: WDE0025: The #Noir collection does not exist. You cannot work with a collection using the Data API before it is created in the Editor.

Anybody know what is my error?

Thanks a lot

Hi,

I believe the issue is using a # for the collection name. That is a naming convention for selecting Wix Elements .

Replace the following line:

wixData.query("#Noir")

Updated Code:

wixData.query("Noir")

thank you Thomas, by now the console doesn’t give me the error but the code doesn’t work🙄