Belphemur / json-db-node-red

Node-RED Node to store easilly
GNU General Public License v3.0
5 stars 17 forks source link

Modified object is returned on next query even when not stored persistently #8

Open konacurrents opened 2 years ago

konacurrents commented 2 years ago

I posted to the node-red forum about an issue I'm having with persistence.

Basically, after a dataOut retrieval, the msg.payload contains the JSON data. I then modify a parameter, such as msg.payload.password, to return the query to the user (but with the password blanked out). This payload is NOT stored.

The next dataIn retrieval for the same query returns the modified in-memory version, instead of going to the values stored in the persistent file.

I found that RED.util.cloneMessage(msg.payload) makes a copy and I can modify that to send on in my flow.

msg.payload = RED.util.cloneMessage(msg.payload);
msg.payload.password = "";
msg.payload.guestPassword = "";

Without the clone message, the next retrieval has a JSON object with an empty password.

For me this wasn't obvious.