Moralis: Updating Objects

Hello there!!!
I wanna ask that how to access an object and update it… I have found only creating a new object and updating it…

In my case, the trigger is called whenever a new token is created… but later on, I want to change some of its attributes… and unable to do it… used the query but it didn’t work out…
as I am a beginner at blockchain development… so need your help guys…

thanks in advance…

1 Like

Hey @naimaghm :wink:

Take a look at Updating Objects

Please note that if you want to update an object using cloud functions you should use save method

If this does not help, please send the entire code.

3 Likes

Hey @Yomoo
have tried this already but it’s creating a new object and then update…and I want to update an existing one…
and yes I have read and watched the tutorial but didn’t get my answer… :roll_eyes: :neutral_face:

1 Like

The rewritten docs code bellow works in Cloud functions:

Moralis.Cloud.define("test", async(request) => {
  const { objId } = request.params;
  const query = new Moralis.Query("GameScore");
  query.equalTo("objectId", objId);
  const queryResult = await query.first();
  queryResult.set("score", 1900);
  return queryResult.save()
});

You can find an object by its parameters(for example objId ) and then overwrite the values you need.

3 Likes

Thanks @Yomoo :hugs:

1 Like