Node-red mongodb update record

#1

Hi friends,

I connect to the node-red server with mqtt and send a json object as follows.
{"nodebolge": "tttttt", "nodename": "device5", "nodeabone": "144", "index": "655477"}

If you have the same record with the "nodename" field, how can I update that record.

[{"id":"82480c90.eb63c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"198a0d21.d320f3","type":"mqtt in","z":"82480c90.eb63c","name":"","topic":"/deneme/#","qos":"0","broker":"20b98e5f.a35d02","x":80,"y":100,"wires":[["e7872a27.108a38"]]},{"id":"ed7155f2.0b3398","type":"influxdb out","z":"82480c90.eb63c","influxdb":"bff5e425.ff6f68","name":"","measurement":"nodes","precision":"","retentionPolicy":"","x":680,"y":80,"wires":},{"id":"e7872a27.108a38","type":"json","z":"82480c90.eb63c","name":"","property":"payload","action":"","pretty":false,"x":210,"y":100,"wires":[["3f92a06b.8a235","f9f53243.c7b2e","4e20cb46.5ae044"]]},{"id":"3f92a06b.8a235","type":"debug","z":"82480c90.eb63c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":390,"y":120,"wires":},{"id":"f9f53243.c7b2e","type":"function","z":"82480c90.eb63c","name":"MQTT to InfluxDB","func":"\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":80,"wires":[["9b5c50ba.dbe6e","ed7155f2.0b3398","b9655963.9c5818"]]},{"id":"9b5c50ba.dbe6e","type":"debug","z":"82480c90.eb63c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":610,"y":40,"wires":},{"id":"b9655963.9c5818","type":"ui_text","z":"82480c90.eb63c","group":"85fb1c35.e8786","order":0,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":590,"y":120,"wires":},{"id":"8e484b23.a5dce8","type":"mongodb2 in","z":"82480c90.eb63c","service":"ext","configNode":"2666b88d.91e6f8","name":"","collection":"cihazlar","operation":"insert","x":310,"y":360,"wires":[["42221050.c7375"]]},{"id":"4e20cb46.5ae044","type":"function","z":"82480c90.eb63c","name":"MQTT to InfluxDB","func":"msg.payload = msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":210,"y":300,"wires":[["8e484b23.a5dce8"]]},{"id":"42221050.c7375","type":"debug","z":"82480c90.eb63c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":410,"y":420,"wires":},{"id":"20b98e5f.a35d02","type":"mqtt-broker","z":"82480c90.eb63c","name":"centos","broker":"192.168.1.104","port":"1883","clientid":"node-red","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""},{"id":"bff5e425.ff6f68","type":"influxdb","z":"","hostname":"192.168.1.104","port":"8086","protocol":"http","database":"enriot","name":"","usetls":false,"tls":""},{"id":"85fb1c35.e8786","type":"ui_group","z":"","name":"Default","tab":"c07006d.07c3af8","disp":true,"width":"6","collapse":false},{"id":"2666b88d.91e6f8","type":"mongodb2","z":"","uri":"mongodb://localhost:27017/ENRIOT","name":"","options":"","parallelism":"-1"},{"id":"c07006d.07c3af8","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

0 Likes

#2
  1. Your flow cannot be imported, this is the same problem as last time, please reread the post on how to post a flow.

  2. What node are you using there are lots of mongodb nodes https://flows.nodered.org/?term=mongodb&type=node&num_pages=1

Assuming you are using node-red-mongodb the message you need to send to update is described in the ReadMe, so that would be a good place to start

0 Likes

#3

You didn't understand me.
I want to update if there is a record in a nodename field.
like the following link

0 Likes

#4

I think it is you that do not understand. You have not responded to questions 1 or 2 that @ukmoose asked.

0 Likes

#5

[{"id":"82480c90.eb63c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"198a0d21.d320f3","type":"mqtt in","z":"82480c90.eb63c","name":"","topic":"/deneme/#","qos":"0","broker":"20b98e5f.a35d02","x":80,"y":100,"wires":[["e7872a27.108a38"]]},{"id":"ed7155f2.0b3398","type":"influxdb out","z":"82480c90.eb63c","influxdb":"bff5e425.ff6f68","name":"","measurement":"nodes","precision":"","retentionPolicy":"","x":680,"y":80,"wires":[]},{"id":"e7872a27.108a38","type":"json","z":"82480c90.eb63c","name":"","property":"payload","action":"","pretty":false,"x":210,"y":100,"wires":[["3f92a06b.8a235","4e20cb46.5ae044","f9f53243.c7b2e"]]},{"id":"3f92a06b.8a235","type":"debug","z":"82480c90.eb63c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":390,"y":100,"wires":[]},{"id":"f9f53243.c7b2e","type":"function","z":"82480c90.eb63c","name":"MQTT to InfluxDB","func":"\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":60,"wires":[["9b5c50ba.dbe6e","ed7155f2.0b3398","b9655963.9c5818"]]},{"id":"9b5c50ba.dbe6e","type":"debug","z":"82480c90.eb63c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":610,"y":40,"wires":[]},{"id":"b9655963.9c5818","type":"ui_text","z":"82480c90.eb63c","group":"85fb1c35.e8786","order":0,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":590,"y":120,"wires":[]},{"id":"8e484b23.a5dce8","type":"mongodb2 in","z":"82480c90.eb63c","service":"ext","configNode":"2666b88d.91e6f8","name":"","collection":"cihazlar","operation":"insert","x":310,"y":360,"wires":[["42221050.c7375"]]},{"id":"4e20cb46.5ae044","type":"function","z":"82480c90.eb63c","name":"MQTT to InfluxDB","func":"msg.payload = msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":210,"y":300,"wires":[["8e484b23.a5dce8"]]},{"id":"42221050.c7375","type":"debug","z":"82480c90.eb63c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":410,"y":420,"wires":[]},{"id":"20b98e5f.a35d02","type":"mqtt-broker","z":"82480c90.eb63c","name":"centos","broker":"192.168.1.104","port":"1883","clientid":"node-red","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""},{"id":"bff5e425.ff6f68","type":"influxdb","z":"","hostname":"192.168.1.104","port":"8086","protocol":"http","database":"enriot","name":"","usetls":false,"tls":""},{"id":"85fb1c35.e8786","type":"ui_group","z":"","name":"Default","tab":"c07006d.07c3af8","disp":true,"width":"6","collapse":false},{"id":"2666b88d.91e6f8","type":"mongodb2","z":"","uri":"mongodb://localhost:27017/ENRIOT","name":"","options":"","parallelism":"-1"},{"id":"c07006d.07c3af8","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

  1. mongodb2
0 Likes

#6

That is still not importable, for future posts how to share a flow is shown here: How to share code or flow json

The link you posted shows how to do it so I'm guessing you have done this now.

0 Likes

#7

Yeah.
I can add data, but what should I do to update the same record

0 Likes

#8

I'm sending the following json data.
I sent the data "nodeName" is the same as the incoming json object how do I get updated according to json line.

Json: { "nodebolge": "Dnme","nodename": "nameAlani", "nodeabone": "abone2", "endeks": "655477" }

var newMsg = {
'collection' : 'cihazlar',
'operation': 'update',
'payload': {
'nodebolge': "ttttt",
'nodename': "nameAlani",
'nodeabone': "abone2",
'endeks': "endeks"
}
};
return newMsg;

0 Likes

#9

The post that you added gives the answer of how to update. Just follow the solution that you provided.

0 Likes

Node-red mongodb2 update