WixData Query

wixData.query("Vote")
  .eq("userId", userId)
  .find()
  .then( (results) => {
 if(results.items.length > 0) {
 let items1 = results.items.id; 

Hi, everyone.
The above code functions as a query (of /to) the collection ‘Vote’ .
It queries the current userId with the field ‘userId’ in the database.
After the query I want to get (return) the items in the field ‘id’.
But the above code is not working. When running, it is returning ‘undefined’.

Fields →

‘undefined’

Thanks,
Ajith

Hi Ajit :raised_hand_with_fingers_splayed:

The issue is in your last line of code.

let items1 = results.items.id;

items is an array, and doesn’t have a property called id.

You need to access the first item in that array, first item might has an “id” field.

let items1 = results.items[0].id;

Hope this helps~!
Ahmad

Hi Ahmad !
Thanks It works !!!

@ajithkrr You’re welcome :wink: