How to set env variable

Have a look in the node red docs.

Possibly the best way would be to first look at the code of the current node, then when you think you understand it, fork that repository and amend that node to do what you want. Once it is working you can send the changes back to the author as a PR to get it included in the standard node.
In fact first raise an issue on the node and offer to help the author implement the feature.

Again that won't work if the node makes a connection to the DB on startup and does not have the code to disconnect and connect to a different db.

This would have to be an optional behaviour if you wanted to update the existing node. Having to check then closing and reopening the connection all the time could potentially make the performance really bad if not implemented properly.