# Node-red mongodb2 update

**URL:** <https://discourse.nodered.org/t/node-red-mongodb2-update/7009>\
**Category:** General\
**Created:** [19 January 2019 09:42 UTC](https://discourse.nodered.org/t/node-red-mongodb2-update/7009 "2019-01-19T09:42:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![turkdoktoru](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/turkdoktoru/32/5111_2.png) [@turkdoktoru](https://discourse.nodered.org/u/turkdoktoru)\
**Post date:** [19 January 2019 09:42 UTC](https://discourse.nodered.org/t/node-red-mongodb2-update/7009/1 "2019-01-19T09:42:02Z")

</div>

Hi friends,

The node-red stream is as follows.  
How do I update with the code specified in "Set message payload function". I can insert insert with the same code, but I can't update the current record.

How do I update the function code?

**Set message payload function**  
msg.payload ={"\_id": msg["\_id"]};  
var msg = {  
'collection' : 'cihazlar',  
'operation': 'updateOne',  
'payload': {  
// '\_id': '5c41cacec3bcb01b705c45b9',  
'nodebolge': 'area',  
'nodename': 'nameField',  
'nodeabone': 'device3',  
'endeks': 'index'  
}  
};  
return msg;

**Flow**

 ![mqtt1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e17541d17a273ee1f8aa059079d8d05c85d91634.png)

**Mongodb2**  
 ![mqtt2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/ef646cd764faafe409d1d3f83d14f47ce155809e.png)

**Switch**  
 ![switch](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0df172192efdb77d256a07f127e56c3d1c132e73.png)

**Set message payload function**  
 ![setmessagepayloadfunction](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c1d852ee00a78e3fc369444b9822bd0a00e1283e.png)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [19 January 2019 10:22 UTC](https://discourse.nodered.org/t/node-red-mongodb2-update/7009/2 "2019-01-19T10:22:42Z")

</div>

Please don't open multiple questions for the same issue. It makes it harder for anyone else who has a similar problem and find this in the future

> [@Node-red mongodb update record](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783/9):
>
> The post that you added gives the answer of how to update. Just follow the solution that you provided.
