How to Prevent Insertion of Duplicate Data to the Database with Node-Red Function Node?

Hi,

I need an help here. I have two text inputs, one drop down and a button on my dashboard ui. I would like to check whether the data from the inputs already available on the database table. If yes, I want to prevent the users from inserting the data. If no, then only I want to allow the users to insert the data successfully.

For example, if the user information already available on the database, then the user unable to enter the same user information again.

I would like to do this by adding a function node with two msg.topic for SELECT and INSERT MySQL command. Is that possible? If yes, how to do it? How to distinguish both msg.topic and return them?

I understand that data duplication prevention can be done on the database itself. If that is the only way, how to return a result that the data already available and the user unable to add the information on dashboard ui?

Hope to hear from you soon. Thanks for helping.

Have a look here:

This is not the only way to do what you want, I'm sure more suggestions will come.

Hi Garry,

Thank you for the suggestion. I'm using MySQL COUNT() Function and get the number of data available. Then I compare with 0 using switch node. It works for me for the moment.