taking column with not empty values from collecion and put to array

Hi does anybody can help me with one thing. I have query which gives me array. Shortly there are items (guests) that are not empty in field g1 or g2 or g3 or g4. Now i need to put into new array all guests. I meand one column “guest” with all guests (g1,g2,g3,g4) not entire items. I need this array to use in different code but i stuck in taking only those columns from collecion.

function getOccupiedSeats () {

return wixData.query(“zakwaterowanie”)

.limit(200) 
.eq("_owner", userId) 
.isNotEmpty("_owner") 
.isNotEmpty("g1") 
.or(wixData.query("zakwaterowanie") 
  .limit(200) 
  .eq("_owner", userId) 
  .isNotEmpty("_owner") 
  .isNotEmpty("g2")) 
.or(wixData.query("zakwaterowanie") 
  .limit(200) 
  .eq("_owner", userId) 
  .isNotEmpty("_owner") 
  .isNotEmpty("g3")) 
.or(wixData.query("zakwaterowanie") 
  .limit(200) 
  .eq("_owner", userId) 
  .isNotEmpty("_owner") 
  .isNotEmpty("g4")) 
 .find() 
.then((result) => { 

return Promise.resolve(result.items);

      }    )          

}

Hi,
So you want to save fields g1,g2,g3,g4 from every item in your collection?
If you do check out the following example code:

let arr = [];
  wixData.query("myCollection")
  .find()
  .then( (results) => {
  let items = results.items;
    for(let i=0; i< items.length; i++){
      arr.push(items[i].g1);
      arr.push(items[i].g2);
      arr.push(items[i].g3);
      arr.push(items[i].g4);
    }
  } )
  .catch( (err) => {
    let errorMsg = err;
  } );

Good luck :slight_smile:
Or

Thanks for replay. After days of thinking i did somethink like this. It works. Do You think Your solution will be quicker than this because its bit similar but i’m not sure if “or” is not taking more time? Is there easy way to get rid of empty and undefined?

function getOccupiedSeats () {

return wixData.query(“zakwaterowanie”)

.limit(200) 
.eq("_owner", userId) 
.isNotEmpty("_owner") 
.isNotEmpty("g1") 

.or(wixData.query(“zakwaterowanie”)
.limit(200)
.eq(“_owner”, userId)
.isNotEmpty(“_owner”)
.isNotEmpty(“g2”))
.or(wixData.query(“zakwaterowanie”)
.limit(200)
.eq(“_owner”, userId)
.isNotEmpty(“_owner”)
.isNotEmpty(“g3”))
.or(wixData.query(“zakwaterowanie”)
.limit(200)
.eq(“_owner”, userId)
.isNotEmpty(“_owner”)
.isNotEmpty(“g4”))
.find()
.then((result) => {

var goscie = [{“imie”: ‘’}]
let options = [{“imie”: ‘’, “label”: ‘All’}];
goscie.push(…result.items.map(continent => {
// let g1=continent.g1
return {“imie”: continent.g1};
}));
goscie.push(…result.items.map(continent => {

return {“imie”: continent.g2};

    } )); 
     goscie.push(...result.items.map(continent => { 

return {“imie”: continent.g3};

    } )); 
     goscie.push(...result.items.map(continent => { 

return {“imie”: continent.g4};

    } )); 

return Promise.resolve(goscie);
})}