Update object after query


Is it possible to update the query object? I’d like to have one object to just keep track off-chain the id of the last created nft. So I thought I would create like a counter for that in DB.

But it looks like you cannot update the query object and I don’t want to create a new one.

          const ERC1155Ids = Moralis.Object.extend("ERC1155Ids");
          const query = new Moralis.Query(ERC1155Ids);
          query.equalTo('objectId', 'JZzg9ec5BT9L31D5jcmMZHAZ');
          const result = await query.first();
          if (result) {
            let erc1155Ids = await result.get('id');
            console.log("Before: ", erc1155Ids);
            result.set('id', ++erc1155Ids)
            console.log("After: ", erc1155Ids);
            await result.save();

console log is like it should be:

Before:  0
After:  1

But it doesn’t update the object in DB at all

I would expect it to work, maybe you can try without ++ and compute the exact value before that line

I can set it to a fixed number like 6725317 and it still doesn’t update. However tbh I’m still using Moralis 0.0.176. But I’m going to try to update to latest release and see if it works.

I don’t think that updating the SDK would make a difference here. You could also try form a cloud function where you can also use master key.

You can also search on google how to do it with parse.

Same thing happens with cloud functions:

Moralis.Cloud.define("erc1155idUpdate", async (request) => {
	const query = new Moralis.Query("ERC1155Ids");
  	query.equalTo("objectId", request.params.objectId);
  	const result = await query.first();
  	let erc1155id = await result.get('id');
  	result.set('id', ++erc1155id);
  	await result.save();
  	erc1155id = await result.get('id');
  	return erc1155id;

What do you mean by ‘do it with parse’?