Search code examples
javascriptsynchronizationparse-serverparse-cloud-code

how to update parse Object synchronized in cloud code then check if it was successfull?


i want synchronized update parse object in cloud code and check if update was successfull?then run some logic and return result ot user. parse use node SDK in parse cloud code and its examples are asynchronized.

here is parse doc example but async.


Solution

  • You just need to use async/await:

    Parse.Cloud.define('myFunction', async req => {
      const GameScore = Parse.Object.extend("GameScore");
      const gameScore = new GameScore();
    
      gameScore.set("score", 1337);
      gameScore.set("playerName", "Sean Plott");
      gameScore.set("cheatMode", false);
      gameScore.set("skills", ["pwnage", "flying"]);
    
      await gameScore.save();
    
      // Now let's update it with some new data. In this case, only cheatMode and score
      // will get sent to the cloud. playerName hasn't changed.
      gameScore.set("cheatMode", true);
      gameScore.set("score", 1338);
    
      await gameScore.save();
    });