Created
October 24, 2016 09:09
-
-
Save pivanov/e2c643a1a0e77fb916936ad1cbb1c448 to your computer and use it in GitHub Desktop.
Backup Parse Class called "Appoinments" to "AppoinmentsBackup"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Parse.Cloud.job("backupAppoinments", function(request, status) { | |
var nowTimeStamp = Date.now(); | |
var timeout = 60 * 60 * 1000; // one hour (run this cloud job each hour) | |
var query = new Parse.Query("Appoinments"); | |
// set a limit | |
query.limit(100); | |
query.equalTo("read", true); | |
query.lessThan("readTime", nowTimeStamp - timeout); | |
query.find().then(function(appoinments) { | |
var promises = []; | |
var BackAppoinments = Parse.Object.extend("AppoinmentsBackup"); | |
_.each(appoinments, function(appoinment) { | |
promises.push(function(appoinment) { | |
var newObject = new BackAppoinments(); | |
// try to backup the ObjectId of Calls | |
newObject.set("AppoinmentId", appoinment.get("objectId")); | |
// for each data column you want to backup | |
newObject.set("data", appoinment.get("data")); | |
// ... | |
return newObject.save(); | |
}(appoinment)); | |
}); | |
// if you want to delete your dat | |
// promises.push(Parse.Object.destroyAll(Appoinments)); | |
// do Promises in Parallel | |
return Parse.Promise.when(promises); | |
}).then(function() { | |
status.success("All Data from Appoinments was moved successfully."); | |
}, function(error) { | |
status.error("error moving data" + error.code + ": " + error.message); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment