Incomplete object returned by a query

Hi everyone :slight_smile:

Here is my question :

After that the user clicks on the button “Profile”, I would like to redirect him either to “First connection” or “profile page” based on either his phone number is completed or not.

Here is a short view of the Members database (as you can see, there is multiple fields) :

Here is my code :

export function profileButton_click(event) {   
 let user = wixUsers.currentUser;
 let userEmail; 
user.getEmail()
  .then( (email) => {
      userEmail = email;     
 } );
 console.log(userEmail)

    wixData.query("Members")
    .eq("mail", userEmail)
    .find()
    .then( (results) => {
 let firstItem = results.items[0]
            console.log(firstItem)
 let fieldValue = firstItem.phone;
 let fieldValue2 = firstItem._id;
        console.log(fieldValue.length)
 
 if (fieldValue.length !== 0) {
       wixLocation.to(`/members/${fieldValue2}`)
     } else {
        wixLocation.to(`/members-first-connection/${fieldValue2}`)
     }      
})}

However, the object returned by the query is this one :

I understand that fieldvalue.length is undefined since firstItem.phone doesn’t exist in the object.

So here is my question :

Why the query doesn’t return all the fields that are on my database ? Am I missing anything ?

Thank you :slight_smile:

Did you already tried to run the code without that error, causing code-line?
I think because the error occurs, the code stops and because of this you get not the fully query. But this is just a suggestion.

Hi, thank you for your answer :slight_smile:
I indeed tried to run the query without the error causing line. However since the error occurs after the query returned the object, it doesn’t affect the object itself. So it’s basically the same thing in the end.

It only returns fields that contain values. If the there’s no value, it won’t be in the results.

Oooooh alright ! Thank you so much !
So is there any way I can code that if there is no value, then rederict to “First connection” and if there is a value, redirect to “profile” ?