Performing complete document updates correctly on mongodb

Hello,

I am new to node-red and Mongo interactions and I am having trouble finding some clear examples of how to perform an update over a document.

I have a constant stream of data coming in my flow, that comes from different devices. every device has his corresponding document on a MongoDB instance which I would like to update every time I get something new from the sensor.

I have been trying with different nodes:

  • node-red-contrib-mongo-client
  • node-red-contrib-mongodb3
  • node-red-mongodb

but can't create a working function node to pass the correct inputs to do an update.

I would like to overwrite the entire document each time and I am trying to filter the find on the device "name".

do you know of any example flow that performs update operations?

more info:

I can update a value via this function:


var newMsg = { 
  'collection': 'collection', 
  'operation': 'update',
  'query': {
      pc:'SENSOR1'
      
  },
  'payload': { 
      $set: {
          ts : 4444
      }
   } 
}; 
return newMsg;

receiving the new document as a payload, how can I send it via the function to update the whole document?

using node-red-mongodb

bumping up :stuck_out_tongue_winking_eye:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.