Is it possible to do nested queries in cloud code?
I want to be able to do something like
var adList = [];
var query2 = new Parse.Query(\"QR\");
var
The second query is asynchronous so wrapping it in a for won't work.
response.success gets triggered before the second query finished so you are returning before actually waiting for the results. I would tell you to move response.success inside of the second success callback of query2 but that won't work either since you are running an async operation synchronously inside a for so you will send the response in the first success.
Don't run an async operation inside a loop. It doesn't work.
I'm not sure what you are trying to accomplish here but you'll have to instantiate a new Query for every call if you want to make as many queries as results.
Again, I'm not sure what is exactly you are trying to do but here is a way you can do something like that:
var adList = [];
var query = new Parse.Query("Campaigns");
query.equalTo("isFeatured", true);
query.find({
success: function(results) {
var queries = [];
for (var i=0; i
Bar in mind that Parse Cloud Code let you run code for aprox 5/7 seconds and this might be very slow if you have a lot of results.
Btw, take a look a Parse's matchesQuery method.
Example taken from their docs:
var Post = Parse.Object.extend("Post");
var Comment = Parse.Object.extend("Comment");
var innerQuery = new Parse.Query(Post);
innerQuery.exists("image");
var query = new Parse.Query(Comment);
query.matchesQuery("post", innerQuery);
query.find({
success: function(comments) {
// comments now contains the comments for posts with images.
}
});