Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Tunde Adegoroye
20,597 PointsParse cloud code query not working
I have a parse cloud code function which i'm using to get some information from one of my classes called SourcesTopData, this is being called in swift whenever the app launches.
The issue i'm having is it seems like the query code i'm using to get this information isn't working. The function being used is below.
Parse.Cloud.define("myNews", function (request, response) {
var newsJsonData = {
"stories": []
};
// Check the params and get the range
if (parseInt(request.params.myoffset) === 0) {
endIndex = 5;
} else {
startIndex = request.params.myoffset;
endIndex = startIndex + 5;
}
var promises = _.each(request.params.keys, function (news_api_key) {
if (request.params.Type == "Top") {
var query = new Parse.Query("SourceTopData");
query.equalTo("guid", news_api_key);
console.log("The api key is " + news_api_key);
query.find({
success: function (results) {
console.log("The results are");
console.log("The icon name is " + results[0].get("icon") + " The source name is " + results[0].get("source") + " The url id is " + results[0].get("guid_url"));
},
error: function () {
console.log("FAIL");
success = false;
response.error("Query lookup failed");
}
});
}
});
Parse.Promise.when(promises).then(function () {
response.success(newsJsonData);
}, function () {
response.error("No stories");
});
});
The line where i am trying to log the columns under the console.log("The results are"); is printing nothing. After moving the logging i've found that the code isn't going into the success or the fail in the query find but i can't seems to figure out why this is since looking at the doc i've set up the Parse.Query properly.
Pasan Premaratne
Treehouse TeacherPasan Premaratne
Treehouse TeacherTunde Adegoroye,
Parse recently shutdown their service. Would that be the issue?