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