Node-RED MongoDB Update Example

hello everyone. i need some help for node-red and mongodb update command. i didn't update my ledButton value. here is my workflow

[{"id":"707a8db8.190a04","type":"tab","label":"Flow 6","disabled":false,"info":""},{"id":"18422fa2.b250e","type":"function","z":"707a8db8.190a04","name":"build operation parameters: filter, update","func":"var filter = msg.payload;\nif (\"string\" == typeof filter) {\n  filter = JSON.parse(filter);\n}\n\nmsg.payload = [\n  filter,\n  {\n    \"$set\": {\n      \"ledButton\": true    \n        \n    }\n  }\n];\n\nreturn msg;\n","outputs":1,"noerr":0,"x":500,"y":280,"wires":[["d5dfb1c.951115"]]},{"id":"d5dfb1c.951115","type":"mongodb2 in","z":"707a8db8.190a04","service":"_ext_","configNode":"3f7edabd.002556","name":"","collection":"button","operation":"findOneAndUpdate","x":710,"y":180,"wires":[["d9faaf65.edeb6"]]},{"id":"664492e7.50550c","type":"inject","z":"707a8db8.190a04","name":"Inject filter","topic":"","payload":"{\"_id\": \"5d5fcdfe6eea790e6066f4c2\"}","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":180,"y":180,"wires":[["18422fa2.b250e"]]},{"id":"d9faaf65.edeb6","type":"debug","z":"707a8db8.190a04","name":"","active":true,"console":"false","complete":"false","x":840,"y":241,"wires":[]},{"id":"3f7edabd.002556","type":"mongodb2","z":"","uri":"mongodb://zgrdev:a1b2c3@ds219040.mlab.com:19040/ads-test","name":"test","options":"","parallelism":"-1"}]

Unfortunately your flow isn't currently importable.Please read the following post How to share code or flow json and then edit the above message.

1 Like