Firestore data update

Hello. With Pipedream, I want to increase the Golds(number) data in my html request time firestore database. But instead of increasing it, it saves the data as it is.

For example:

I want it to be current value(100) + {{steps.trigger.event.query.rewards}} but instead of 100 + it just does {{steps.trigger.event.query.rewards}}. So instead of increasing the number, it directly sets it to {{steps.trigger.event.query.rewards}}.

Hi @eminhasan345

First off, welcome to the Pipedream community. Happy to have you!

I want it to be current value(100) + {{steps.trigger.event.query.rewards}} but instead of 100 + it just does {{steps.trigger.event.query.rewards}}.

You’ll need to include the math operation within the JS evaluation for it to work properly:

 {{value + steps.trigger.event.query.rewards}}

Also, verify that the query.rewards is being interpreted as an integer or float type. If it’s interpreted as a string, then the addition won’t work as you’d expect.

Hope this helps!

how can i include math operation within JS evaluation?

Sorry, from your original message I thought value was defined:

I want it to be current value(100) + {{steps.trigger.event.query.rewards}}

I’m not sure where you’re passing this value from. But if it’s a static amount then you can do something like:

 {{ 100 + steps.trigger.event.query.rewards }}

It’s not a static amount. Variable. This is exactly the problem :frowning:

Great, then where are you storing this variable in? A Node.js step? From the trigger or some other action?

Once you’ve answered that question, then you can use Step Exports to reference that variable in your JS evaluation:

For example, if you had a step called node_js that returns 100, then the step export for that would be steps.node_js.$return_value.

Then you could reference it in the JS evaluation:

{{ steps.node_js.$return_value + steps.trigger.event.query.rewards }}

Hmm I get it. I need to get current value from firebase Firestore using Node js. But I don’t know how to do this. Can you give a code sample?

You might be able to use this Node.js scaffolding to retrieve a record from a Firestore database:

export default defineComponent({
  props: {
    firestore: {
      type: "app",
      app: "firestore",
    },
    collection: {
      type: "string",
      label: "Collection Name",
    },
    documentId: {
      type: "string",
      label: "Document ID",
    },
  },
  async run({ steps, $ }) {
    const response = await this.firestore.getDocument({
      collection: this.collection,
      documentId: this.documentId,
    });

    if (response.exists) {
      return response.data();
    } else {
      console.log("No such document!");
    }
  },
});

Please note, this is generated by our GPT-3 bot Mario in our public Slack workspace. It’s not been tested, but usually Mario is pretty good at generating components like these.

Something seems to be missing