How to use .eq to filter a collection by value of Boolean field

I am trying to fill a dropdown list from a collection. This collection has a field (named “ViewOnly”) of type Boolean. I want only the records that have a value of true to be returned by the query. If I comment out the filtering code (i.e. .eq"viewOnly"…) the query successfully returns all records (not what I want) and the dropdown list is successfully populated. If I introduce the filtering code I get no results returned.

I have tried 3 variations on the filtering code:

a) my initial attempt:
wixData.query(“SubmissionStatus”).ascending(“status”)
.eq(“viewOnly”, true )

b) an attempt as a result of a search of previous posts in this forum:
wixData.query(“SubmissionStatus”).ascending(“status”)
.eq(“viewOnly”, Boolean( true ))

c) a final ridiculous and desperate attempt of my own where I compare to a literal:
wixData.query(“SubmissionStatus”).ascending(“status”)
.eq(“viewOnly”, " true" )

Any suggestions would be very appreciated (especially any that work!) Thank you very much.

In my original post I forgot to mention something that might be helpful: I also tried the filtering code such that I am filtering on a text field in the same collection. This is NOT what I want to do, but I simply did this to check that the code is otherwise working. So this code was:

wixData.query(“SubmissionStatus”).ascending(“status”)
.eq(“status”, “Awaiting Review”)

This code worked and successfully returned a filtered set of records from the collection, which then populated the dropdown list. However I do not want to actually filter on this text field, I simply did it to confirm my code was otherwise working. I need to filter on the Boolean field “ViewOnly” as I originally posted and this is what I am struggling to do. Thanks.

Is this not a simple question? How to check if a Boolean field is true?

option A should work (but maybe the code you have after it and you haven’t posted is not).

Hi @oconnorpeter9 , were you ever able to come up with a solution for this? I am having the same issue.

I can’t remember how this was resolved back in 2019, sorry. However, on a site I’m working on now I have this code which is working fine:

$w ( "#dsIncorrectLessons" ). setFilter ( wixData . filter () 
    . eq ( "fkStudent" ,  studentId ) 
    . eq ( "hasQuestions" ,  **true** ) 
); 

The problem is, that the code above looks to be the same as the code that wasn’t working back in 2019, so I suspect I can’t help much. Very sorry!

That’s all right, thanks so much for the quick response! Yep, I have the exact same syntax in mine… I’ve been going around in circles all morning.

a) My initial attempt:
RIGHT-VERION: (but why?)

wixData.query("SubmissionStatus")            
.eq("viewOnly", true) <-- the real BOOLEAN-VALUE !!!
.ascending("status")
.find()
.then(()=>{ ... });            

b) An attempt as a result of a search of previous posts in this forum:

wixData.query("SubmissionStatus")            
.eq("viewOnly", Boolean(true)) 
.ascending("status")
.find()
.then(()=>{ ... });

c) A final ridiculous and desperate attempt of my own where I compare to a literal:

wixData.query("SubmissionStatus")            
.eq("viewOnly", "true") //<--- This can work, but on string-fields only!!!
.ascending("status")
.find()
.then(()=>{ ... });

Yep, that’s the syntax I’m using.

wixData . query ( “EventPhotos” )
//.eq(“publish”, true) ------> doesn’t work
. limit ( 15 )
. isNotEmpty ( “thumbnail” )
. descending ( “eventDate” )
. contains ( “search” , $w ( “#searchbox” ). value )

How to Combine Fixed Filters with Optional Filters?

Hi, I found this thread close to solving my issue. My case varies as follows;

I have dropdown filters run by velo code. This overwrites the filters set via dataset settings, whenever a dropdown option is selected. How do I maintain a Boolean filter fixed always? This constant filter is of a different field (‘hide’, false).
I’ll show 3 of my 7 dropdowns.

import wixData from 'wix-data';

$w.onReady(async function () {
    await setupCountriesDropdown();
    setupSubjectDropdown();
    setupLevelDropdown();
    setupCapacityDropdown();
});

function setupSubjectDropdown() {
    $w("#subjectDropdown").onChange(filterAndApply);
}

function setupLevelDropdown() {
    $w("#levelDropdown").onChange(filterAndApply);
}

function setupCapacityDropdown() {
    $w("#capacityDropdown").onChange(filterAndApply);
}


async function filterAndApply() {

    let filter = wixData.filter();

    const subject = $w("#subjectDropdown").value;
    if (subject) {
        filter = filter.ge("subjects", subject);
    }

    const level = $w("#levelDropdown").value;
    if (level) {
        filter = filter.ge("level", level);
    }

    const capacity = $w("#capacityDropdown").value;
    if (capacity) {
        filter = filter.ge("capacity", capacity);
    }

    $w("#listingsDataset").setFilter(filter);
}