I am working on writing some Parse Cloud Code that pulls JSON from a third party API. I would like to modify it, check and see if it already exists and if not, save it. I am having troubles retaining the object after checking if it exists.
Here is an example of what I am trying to do. When I get to the success block, I need the original car object so that I can save it to the parse db. It is undefined though. I am new to JS and am probably missing something obvious here.
for (var j = 0, leng = cars.length; j < leng; ++j) {
var car = cars[j];
var Car = Parse.Object.extend("Car");
var query = new Parse.Query(Car);
query.equalTo("dodge", car.model);
query.find({
success: function(results) {
if (results.length === 0) {
//save car... but here car is undefined.
}
},
error: function(error) {
console.error("Error: " + error.code + " " + error.message);
}
});
}
If anyone could point me n the right direction, I would really appreciate it. Thanks!