Search and show result if contain record

Hi,
I need help with a simple database query. I use dynamic pages for news. Within the database structure, I have created a field with uploading a document (attachment) and I would like to display a vector element on the site only if a file will be stored (uploaded) in the database. I try this function, but it doesn’t work. Anyone can help ?
Thank you in advance,
Jan

import wixData from ‘wix-data’ ;

// For full API documentation, including code examples, visit Velo API Reference - Wix.com

$w.onReady( function () {
$w( “#dynamicDataset” ).setFilter(wixData.filter()
.eq( “attachment” ).value)
.then(() => {
console.log( “Dataset is now filtered” );
let count = $w( “#dynamicDataset” ).getTotalCount();
if (count > 0 ) {
$w( “#attachment” ).show();
}
else {
// tell that there are no results
}
})
. catch ((err) => {
console.log(err);
});
});

Most likely the dataset is not available yet even though the page is ready. You need to put your code inside of a dataset onReady() event handler to ensure that the dataset is ready when you try to use it.

The Dataset is ready, but I don’t know what does it mean that “the given filter object is invalid”, why?

Without the dataset’s onReady() function you can’t be sure the dataset is ready.

This filter option is incorrect:

    .eq("attachment").value)

It should be something like this:

    .eq("attachment"), value)

See the .eq() API for information and examples.