[SOLVED] Perform Query on Array Key for Class User?

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.


So click “Developer” tag and then search for User’s where “Developer” is a value in the array “skillSet”


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 and return “invalid function”

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.select('username', 'userLocation', 'bio', 'profilePic', 'createdAt',"skillSet");
  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'){    
          "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!

1 Like

The issue was that I was passing the value in the array, rather than the array itself. Thanks, this link helped me catch that!