How to query multiple fields in collection?

Hi.
I have a “VOTES” collection with fields - questionId (text) and roomNo (number), also there some more fields but it is not important here.

Here is a function:

export function removeVotesFor(pQuestionId, pRoomNo) {
console.log(“-> Searching votes [ Q=” + pQuestionId + “, R=” + pRoomNo + " ]…");

wixData.query("VOTES") 
    .contains("questionId", pQuestionId) 
    .and( wixData.query("VOTES").contains("roomNo", pRoomNo) )         
    .find() 
    .then( (results) => { 
        onVotesFound(results);             
    } ) 
    . **catch** ( (error) => { 

let errorMsg = error.message;
let code = error.code;
console.log("!Votes.Qry.ERR# " + code + “, msg:” + errorMsg);
} );
}

I need to query collection by 2 fields - questionId and roomNo .
I searched this forum and tried to do it in 2 ways I found here:
1)
wixData.query(“VOTES”)
.contains(“questionId”, pQuestionId)
.contains(“roomNo”, pRoomNo)
.find().then( … )

  1. wixData.query(“VOTES”)
    .contains(“questionId”, pQuestionId)
    .and( wixData.query(“VOTES”).contains(“roomNo”, pRoomNo) )
    .find().then( … )

Both variants does not work! :frowning:
I can clearly see that collection contains lot of records with specified qusetionId and roomNo.

How to query collection by 2 (or more fields) then?

Also I seen strange error message:
!Votes.Qry.ERR# WD_VALIDATION_ERROR, msg:Failed to perform query on [VOTES].
Invalid .contains parameter value [Number]. .contains parameter must be a String.

I tried to pRoomNo.toString() instead of pRoomNo but nothing changed - it was still not able to find appropriate records.
What are rules to match fields datatypes? Why I seen such error message if roomNo is numeric and search parameter also numeric?

Hi
I check the WixDataQuery, and can’t find .and() function. Maybe you can’t use it. I see .or() function. And the example is for one field, see below
import wixData from ‘wix-data’;
// …
wixData.query(“myCollection”)
.lt(“age”, 25)
.or( wixData.query(“myCollection”)
.gt(“age”, 65) )
.find() .then( (results) => {
let items = results.items;

; } );

I am interested with query multiple fields. I hope someone can answer this question.

Yes, you are right. I have not seen .and() function in docs. I just made a guess and made it similar to .or() function.
But I need exactly .and().

Finally, I implemented a workaround - I queries all records by field1 and then use script function to filter out only records which has correct value in field2. That works fine but I did hope WIX should have a normal API for querying by multiple fields.

I found one solution. But I am not sure that is “and” or not. I have made a vedio

Please test that way. IF it is "and’ , please let me know.