Get all id from the query result

Hello Reader,

I would like to get all the ID’s from the query result.

I have tired something like res.items.id. But its not returning all the ID’s

wixData.query(“tableName”).find.then((res)=>{
res.items.id
})

Can some one help me out on this?

Maybe there’s a simpler way to do it, but you can create an array (idResults) of the results id’s using forEach:

 wixData.query("collection")
 .find()
.then((results) => {
 let idResults = []
 results.items.forEach(function(element){
      idResults.push(element._id);
    })
  });

Then you can convert it into string if you like.

Thanks J!! Just curious if wix have any methods to return all values?

No problem. I don’t know. Maybe someone else?

Now that we have .distinct(), it’s easier:

wixData.query("collection")
 .distinct("_id")
.then((res) => {
 let idResults = res.items;
  });
1 Like