WIX Data Query

Hello,

What is best Wix data query I can use if I want to get all rows from one collection that do not have an instance (row) in another collection? (by a key)

it workes for me but i’m not pro coder. still working. function getguest takes all guest (collection 1) function getoccupiedrooms gets id of all guest that are in rooms but it doeasnt matter its collection 2. So i took all ids from collection2 and in bezstolow function filter collection1 by those ids. It workes but i’m not sure if its very coorect. For sure i dont catch errors and i should.

async function bezstolow(x) {

let goscie = await getguest();
let zajete = await getOccupiedRooms();
//console.log(zajete);
//for (let i = 0; i < goscie.length-1; i++) {
var filarray = goscie.filter(filterByID)

function filterByID(item) {
if (zajete.includes(item.value)) {
return false ;
}
// invalidEntries++;
return true ;
}

function getOccupiedRooms() {
let arr = [];
return wixData.query(“stoly”)
.eq(“_owner”, userId)
.find()
.then((results) => {
let items = results.items;
for ( let i = 0; i < items.length; i++) {
arr.push(items[i].sg1); //sg1 is a name of field in collection. i took here all ids

        } 
        arr = arr.filter( **function**  (e) {  **return**  e });  // i take out emty fields here so maybe you will not need to do it 

return arr
})
}

function getguest() {
let guestarray = [{ “value”: ‘’, “label”: ‘zwolnij miejsce’ }];
return wixData.query(“listagosci”)
.eq(“_owner”, userId)
.ascending(“imie”)
.find()
.then((results) => {
let items = results.items;
for ( let i = 0; i < items.length; i++) {

            guestarray.push(...results.items.map(continent => { 

return { “value”: continent._id, “label”: continent.imie };
}))
guestarray = guestarray.filter( function (e) { return e });
return guestarray
}
})
}

thank you! I did something similar in the code but I was wondering if it’s possible to do it only with WixData Query…