# Write Data to database in interval

**URL:** <https://discourse.nodered.org/t/write-data-to-database-in-interval/67485>\
**Category:** Dashboard\
**Created:** [8 September 2022 14:56 UTC](https://discourse.nodered.org/t/write-data-to-database-in-interval/67485 "2022-09-08T14:56:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Janaros](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/janaros/32/67506_2.png) [@Janaros](https://discourse.nodered.org/u/Janaros)\
**Post date:** [8 September 2022 14:56 UTC](https://discourse.nodered.org/t/write-data-to-database-in-interval/67485/1 "2022-09-08T14:56:36Z")

</div>

Hello,  
I have the following problem:

I get data sent every second via MQTT.  
However, I only want to write this data to the database every 30 seconds, otherwise it will become too large.  
Currently, the data comes in via MQTT, I write the SQL statement and then write this to the database.  
How can I ensure that it is only triggered every 30 seconds? Unfortunately, I can't change anything about the MQTT push.

Thank you very much for your help.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [8 September 2022 15:06 UTC](https://discourse.nodered.org/t/write-data-to-database-in-interval/67485/2 "2022-09-08T15:06:07Z")

</div>

Hi @Janaros 😀

You can use a filter node set to rate limit: 1 msg per 30 sec (or is it 2msg per minute?), discard intermediate messages.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 September 2022 15:08 UTC](https://discourse.nodered.org/t/write-data-to-database-in-interval/67485/3 "2022-09-08T15:08:56Z")

</div>

> [@jbudd](#):
>
> use a filter node

Did you mean a Delay node?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [8 September 2022 15:21 UTC](https://discourse.nodered.org/t/write-data-to-database-in-interval/67485/4 "2022-09-08T15:21:38Z")

</div>

I probably do, thanks.

I'm not in front of a computer just now so I said the first thing that entered my head!

Lucky it wasn't my shopping list or something...

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 September 2022 15:29 UTC](https://discourse.nodered.org/t/write-data-to-database-in-interval/67485/5 "2022-09-08T15:29:29Z")

</div>

@Janaros, if you use a Delay node as suggested, and set it to Rate Limit for Each Message topic, and make sure all messages have the same topic, which I guess they will as they are coming from MQTT, then it will release the messages on the minute and half minute, which may be desirable for nice timestamps in the database. If you leave at the default of All Messages then they will not (generally) be on the minute/half minute.

---

<div class="post-metadata">

**Author:** ![Janaros](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/janaros/32/67506_2.png) [@Janaros](https://discourse.nodered.org/u/Janaros)\
**Post date:** [12 September 2022 15:10 UTC](https://discourse.nodered.org/t/write-data-to-database-in-interval/67485/6 "2022-09-12T15:10:48Z")

</div>

Thank you.  
The Delay node worked fine!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [12 October 2022 15:10 UTC](https://discourse.nodered.org/t/write-data-to-database-in-interval/67485/7 "2022-10-12T15:10:52Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
