# Performing complete document updates correctly on mongodb

**URL:** <https://discourse.nodered.org/t/performing-complete-document-updates-correctly-on-mongodb/29723>\
**Category:** General\
**Created:** [8 July 2020 16:24 UTC](https://discourse.nodered.org/t/performing-complete-document-updates-correctly-on-mongodb/29723 "2020-07-08T16:24:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![freddyrm](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@freddyrm](https://discourse.nodered.org/u/freddyrm)\
**Post date:** [8 July 2020 16:24 UTC](https://discourse.nodered.org/t/performing-complete-document-updates-correctly-on-mongodb/29723/1 "2020-07-08T16:24:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![freddyrm](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@freddyrm](https://discourse.nodered.org/u/freddyrm)\
**Post date:** [8 July 2020 16:38 UTC](https://discourse.nodered.org/t/performing-complete-document-updates-correctly-on-mongodb/29723/3 "2020-07-08T16:38:18Z")

</div>

more info:

I can update a value via this function:

```auto

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

---

<div class="post-metadata">

**Author:** ![freddyrm](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@freddyrm](https://discourse.nodered.org/u/freddyrm)\
**Post date:** [9 July 2020 09:51 UTC](https://discourse.nodered.org/t/performing-complete-document-updates-correctly-on-mongodb/29723/4 "2020-07-09T09:51:38Z")

</div>

bumping up 😜

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 September 2020 09:51 UTC](https://discourse.nodered.org/t/performing-complete-document-updates-correctly-on-mongodb/29723/5 "2020-09-07T09:51:39Z")

</div>

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