0

I'm approaching Parse Cloud Code at the moment and to learn i'm checking some basic examples. I have a class named MeetingObject in my parse data base. This class has a field "meetingDateAndTime". I created a background job that check for objects older than the current time and destroy them. I would like the see in the parse Info Log the objectId of the destroyed objects but i can only see the success message, not the log. I tried also using result.objectId. Maybe the "result" variable i'm using is not an Array. What am i doing wrong?

Parse.Cloud.job("deleteOldMeetings", function(request, status) {
var query = new Parse.Query("MeetingObject");            
var currentDate = new Date();                
query.lessThan("meetingDateAndTime", currentDate);
query.find({          
success:function(results) {   
    for (var i = 0, len = results.length; i < len; i++) {
        var result = results[i];
        console.log("Destroyed object.objectId: "+result.get("objectId"));
        result.destroy({});
    }
    status.success("Success.");
},                
error: function(error) {
    status.error("Uh oh, something went wrong.");
    console.log("Failed!");
}
})
});
5
  • Are the objects being destroyed? Commented Sep 24, 2014 at 16:26
  • Try moving the console.log statement immediately above the call to destroy. Also, the correct parse.com syntax for getting an attribute of an object is to use get: result.get("objectId"), not result["objectId"]. You should also consider using the destroyAll method, to destroy a list of objects in one operation. Commented Sep 24, 2014 at 16:30
  • I edited the code with the changes you suggested and tried in parse and the log is this: "Destroyed object.objectId: undefined". I would prefer to use the simple destroy instead of destroyAll because i need to do also some changes on the user that created the meeting so maybe it's best to make these changes in the loop. Commented Sep 24, 2014 at 18:15
  • Ok. For the object id, I think you can use just id. result.id. But you can't log that after you have destroyed it. That's probably why you didn't see anything in the logs. Commented Sep 24, 2014 at 18:44
  • It works. Thanks a lot. If you want to write an answer i will accept it ;) Commented Sep 24, 2014 at 21:41

1 Answer 1

1
  • To get the id of a parse object called "thing": thing.id
  • To get any other attribute (call it "attr") of a parse object called "thing": thing.get("attr")
  • You can't refer to an object after it has been destroyed.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.