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.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!