Array Data of User Undefined

Hello! Iā€™m trying to utilize an array attribute under the User object and am getting undefined as a response. Upon loading a userā€™s own profile, the array was set with useState in react to an active component and then used to map the array values to a set of tags. This worked for less than a day and then stopped working. Iā€™ve update the Moralis server. Here is a simple log of the data showing the result as undefined:

      const skillReveal = () => {
          console.log(user.attributes.rate);
          console.log(user.attributes.contactForPricing);
          console.log(user.attributes.skillSet);   //<= this is the array
      }

Here are the logged results with the array as undefined: image

Here is the matching data entries in the Moralis database under the User class
image

Any help would be appreciated. In a different part of my app I query Users based on their name and return the user attributes as an array of results, and for some reason here the attribute array ā€œskillSetā€ displays, however not using ā€œuserā€ in react through ā€œuseMoralis()ā€
image

I saw this in other forum post: const {user, refetchUserData} = useMoralis();, maybe using refetchUserData makes that array data to appear.

Not sure why this was necessary but it did work! Thank you much cryptokid

In my app I save a set of skill tags in an array assigned to the User Class. Iā€™m performing a cloud function that queries Users for a matching value in the array ā€œskillSetā€ after a button is clicked for the corresponding tag.

image

So click ā€œDeveloperā€ tag and then search for Userā€™s where ā€œDeveloperā€ is a value in the array ā€œskillSetā€

image

How can we query a value that is within this array? I read the docs and canā€™t find any instructions for a query function to find a value saved in an array that is a key of an object such as I have here. I tried query.containedIn(ā€œskillSetā€, ā€œDeveloperā€) and query.equalTo(ā€œskillSetā€, ā€œDeveloperā€) but these donā€™t appear to be valid for an array.

My cloud function is currently the following, however itā€™s not producing any results:

Moralis.Cloud.define("searchUsersByTag", async (request) => {
  const Profiles = Moralis.Object.extend("User");
  let query = new Parse.Query(Profiles);
  query.exists('skillSet');  
  query.select('username', 'userLocation', 'bio', 'profilePic', 'createdAt',"skillSet");
  query.descending('createdAt');
  const queryResults = await query.find({useMasterKey:true});
  const results = [];  
  for (let i = 0; i < queryResults.length; ++i) {
    if (queryResults[i].attributes.skillSet.includes(request.params.skillTag)) {
      if(typeof queryResults[i].attributes.profilePic !== 'undefined'){    
        results.push({
          "username": queryResults[i].attributes.username,
          "location": queryResults[i].attributes.userLocation,   
          "bio": queryResults[i].attributes.bio,       
          "profilePic": queryResults[i].attributes.profilePic._url,
          "skillSet": queryResults[i].attributes.skillSet,
        });
      };
    }
  }
  return results;
});

Thanks for the help!

I think that I tried to answer to this one in a separate thread

1 Like