# Node-red mongodb update record

**URL:** <https://discourse.nodered.org/t/node-red-mongodb-update-record/6783>\
**Category:** General\
**Created:** [14 January 2019 09:21 UTC](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783 "2019-01-14T09:21:34Z")\
**Posts on this page:** 15\
**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:** [14 January 2019 09:21 UTC](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783/1 "2019-01-14T09:21:34Z")

</div>

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.

 ![mqtt](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/47a7dd11f72cbf365ca2a828a61d2e0a52beaa23.png)

[{"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}]

---

<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:** [14 January 2019 09:28 UTC](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783/2 "2019-01-14T09:28:04Z")

</div>

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](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

---

<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:** [14 January 2019 13:13 UTC](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783/3 "2019-01-14T13:13:11Z")

</div>

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

> <https://stackoverflow.com/questions/43477040/update-record-in-monogodb-using-node-red>

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 January 2019 13:56 UTC](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783/4 "2019-01-14T13:56:37Z")

</div>

> [@turkdoktoru](#):
>
> You didn't understand me.

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

---

<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:** [14 January 2019 14:08 UTC](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783/5 "2019-01-14T14:08:25Z")

</div>

1. 

[{"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

---

<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:** [14 January 2019 14:19 UTC](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783/6 "2019-01-14T14:19:12Z")

</div>

That is still not importable, for future posts how to share a flow is shown here: [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

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

---

<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:** [14 January 2019 14:27 UTC](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783/7 "2019-01-14T14:27:07Z")

</div>

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

![mqtt](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6b5068a4136a594c7bb5c40b243f57018b9eed98.png)

---

<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:** [16 January 2019 07:45 UTC](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783/8 "2019-01-16T07:45:58Z")

</div>

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;

---

<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:** [16 January 2019 07:59 UTC](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783/9 "2019-01-16T07:59:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![miobox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/miobox/32/27075_2.png) [@miobox](https://discourse.nodered.org/u/miobox)\
**Post date:** [10 August 2020 01:44 UTC](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783/10 "2020-08-10T01:44:34Z")

</div>

I have tried to use the node mongodb2 and mongodb3 to try to update a record that is written, without succeeding. Could someone help me to review my structure and validate what may be happening?

The objective is to be able to add an object to a record that is already stored using the "\_id" as a filter for the update.

```auto
[{"id":"8bf4e066.fb891","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"fdd747ef.bc9c38","type":"mongodb3 in","z":"8bf4e066.fb891","service":"_ext_","configNode":"5e1ddbe0.796184","name":"","collection":"","operation":"update","x":460,"y":140,"wires":[["3411da85.307a66"]]},{"id":"3411da85.307a66","type":"debug","z":"8bf4e066.fb891","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":260,"wires":[]},{"id":"9ddb94a8.11ba58","type":"inject","z":"8bf4e066.fb891","name":"","props":[{"p":"topic","vt":"str"},{"p":"payload.query","v":"{\"_id\"=\"5f30320db06b690010296077\"}","vt":"json"},{"p":"payload"},{"p":"collection","v":"PLC_DRIYPAC_1","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"\"status\":\"203\"","payloadType":"str","x":110,"y":400,"wires":[[]]},{"id":"9e5e4b61.f90098","type":"inject","z":"8bf4e066.fb891","name":"","props":[{"p":"collection","v":"PLC_DRIYPAC_1","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"$match\":{\"_id\":\"5f30320db06b690010296072\"},\"$set\":{\"sys.status\":\"203\"}}","payloadType":"json","x":270,"y":340,"wires":[["21f5de0.96e9f22"]]},{"id":"21f5de0.96e9f22","type":"mongodb in","z":"8bf4e066.fb891","mongodb":"cd1be4f1.fcbb98","name":"Data Collection","collection":"","operation":"aggregate","x":440,"y":340,"wires":[["3411da85.307a66"]]},{"id":"1c319556.f25b8b","type":"function","z":"8bf4e066.fb891","name":"insert (or delete)","func":"var newMsg = {};\nnewMsg.collection = 'PLC_DRIYPAC_1';\nnewMsg.payload = {_id:(\"5f30320db06b690010296072\")},{$set:{\"syn\":{\"status\":\"203\"}}}\nreturn newMsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":260,"y":140,"wires":[["fdd747ef.bc9c38"]]},{"id":"4086cab3.bc2b64","type":"mongodb-node","z":"8bf4e066.fb891","mongodb":"a5ba9623.f01b88","name":"","collection":"","operation":"update","upsert":false,"multi":false,"x":200,"y":440,"wires":[[]]},{"id":"33bff2c3.3bc00e","type":"inject","z":"8bf4e066.fb891","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":80,"wires":[["1c319556.f25b8b"]]},{"id":"5e1ddbe0.796184","type":"mongodb3","z":"","uri":"mongodb://172.17.0.3:27017/miobox?authSource=admin","name":"miobox","options":"","parallelism":"-1"},{"id":"cd1be4f1.fcbb98","type":"mongodb","z":"","hostname":"172.17.0.3","port":"27017","db":"miobox?authSource=admin","name":""},{"id":"a5ba9623.f01b88","type":"mongodb-config","z":"","hostname":"172.17.0.3","port":"27017","db":"miobox?authSource=admin","name":""}]

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [10 August 2020 11:12 UTC](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783/12 "2020-08-10T11:12:21Z")

</div>

Hi,

i dont know about mongodb2 or mongodb3  
but I have been testing **node-red-contrib-mongodb** version 0.3.4

and you can use the mongo node operation set to " **update**" and use a **function** before it with example :

```auto
var newMsg = {};
newMsg.collection = 'PLC_DRIYPAC_1';
newMsg.query = {"_id": "5f3123aa60ac283b8a7e21f0"};
newMsg.payload = {"$set": {"status": "777"}};

return newMsg;

```

a test flow example :

```auto
[{"id":"1aa86ea6.d665a1","type":"debug","z":"58d20878.b6eef8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":160,"wires":[]},{"id":"4207f55c.7ac6e4","type":"function","z":"58d20878.b6eef8","name":"insert","func":"var newMsg = {};\nnewMsg.collection = 'PLC_DRIYPAC_1';\nnewMsg.payload = {\"status\":\"203\"}\nreturn newMsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":160,"wires":[["83ff43b1.59ece8"]]},{"id":"28f711dc.7848be","type":"inject","z":"58d20878.b6eef8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":80,"wires":[["4207f55c.7ac6e4"]]},{"id":"83ff43b1.59ece8","type":"mongodb-node","z":"58d20878.b6eef8","mongodb":"15e56f9b.d519c8","name":"","collection":"","operation":"insert","upsert":false,"multi":false,"x":620,"y":160,"wires":[["1aa86ea6.d665a1"]]},{"id":"74044eac.e0484","type":"debug","z":"58d20878.b6eef8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":930,"y":400,"wires":[]},{"id":"c782a26e.9ddde8","type":"function","z":"58d20878.b6eef8","name":"find","func":"var newMsg = {};\nnewMsg.collection = 'PLC_DRIYPAC_1';\nnewMsg.payload = {};\nreturn newMsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":350,"y":400,"wires":[["6bccaad7.d79244"]]},{"id":"eda26919.0cd938","type":"inject","z":"58d20878.b6eef8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":320,"wires":[["c782a26e.9ddde8"]]},{"id":"6bccaad7.d79244","type":"mongodb-node","z":"58d20878.b6eef8","mongodb":"15e56f9b.d519c8","name":"","collection":"","operation":"find","upsert":false,"multi":false,"x":680,"y":400,"wires":[["74044eac.e0484"]]},{"id":"4c8a24c8.246d44","type":"debug","z":"58d20878.b6eef8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":930,"y":620,"wires":[]},{"id":"df180e49.f0c2e","type":"function","z":"58d20878.b6eef8","name":"update","func":"//const { ObjectId } = global.get('mongodb');\n\nvar newMsg = {};\nnewMsg.collection = 'PLC_DRIYPAC_1';\nnewMsg.query = {\"_id\": \"5f312ae860ac283b8a7e21f1\"};\nnewMsg.payload = {\"$set\": {\"status\": \"777\"}};\n\nreturn newMsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":600,"wires":[["76a1ac70.b7f2c4"]]},{"id":"7221dfd6.d3ef7","type":"inject","z":"58d20878.b6eef8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":540,"wires":[["df180e49.f0c2e"]]},{"id":"76a1ac70.b7f2c4","type":"mongodb-node","z":"58d20878.b6eef8","mongodb":"15e56f9b.d519c8","name":"","collection":"","operation":"update","upsert":false,"multi":false,"x":680,"y":620,"wires":[["4c8a24c8.246d44"]]},{"id":"15e56f9b.d519c8","type":"mongodb-config","z":"","hostname":"127.0.0.1","port":"27017","name":""}]

```

---

<div class="post-metadata">

**Author:** ![miobox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/miobox/32/27075_2.png) [@miobox](https://discourse.nodered.org/u/miobox)\
**Post date:** [10 August 2020 13:50 UTC](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783/13 "2020-08-10T13:50:25Z")

</div>

Great!

It is already working without problems, I am going to make some changes to adapt the data but I could say that it will work.

I always got a response that replaced all the stored data.

 ![Node-red Mongo](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/c/acb6728e1687b1613db02d232381c14ea39332c5.png)

---

<div class="post-metadata">

**Author:** ![jaroslavhuss](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jaroslavhuss/32/59469_2.png) [@jaroslavhuss](https://discourse.nodered.org/u/jaroslavhuss)\
**Post date:** [2 April 2022 14:22 UTC](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783/14 "2022-04-02T14:22:44Z")

</div>

Hello - your message helped me a lot! For one record this works like a charm! But how the newMsg.query would look like if I want to update many IDs with the same message.paylod? After like 6 hours I am not still able to find any solution.

My query is like this:

```auto
{
    "_id": {
        "$in": [
            "6242170245341c11dc2133da",
            "6242173e45341c11dc2133dc"
        ]
    }
}

```

A tried many variations and I am super lost now...

I welcome any advice 🙂

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [2 April 2022 17:01 UTC](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783/15 "2022-04-02T17:01:51Z")

</div>

Hello .. i tried the `$in` array of \_id strings syntax also without success ..

what worked for me in the end is to use the special `ObjectId` around each id  
but in order to use that you must first load the mongodb library,  
using Node-red's `functionExternalModules` option ([link](https://nodered.org/docs/user-guide/writing-functions#using-the-functionexternalmodules-option))

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/3/a386ed58798688d281b659a7b827a7599be919b6.png)

Then in the Function

```auto
let ObjectId = mongodb.ObjectId

let newMsg = {};

newMsg.query = { "_id": { "$in": [ObjectId("60000f1879d9790bac657a94"), ObjectId("6000162079d9790bac657a95")] } };

newMsg.payload = { "$set": { "testField": 888 } };
    
return newMsg;

```

---

<div class="post-metadata">

**Author:** ![jaroslavhuss](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jaroslavhuss/32/59469_2.png) [@jaroslavhuss](https://discourse.nodered.org/u/jaroslavhuss)\
**Post date:** [2 April 2022 17:20 UTC](https://discourse.nodered.org/t/node-red-mongodb-update-record/6783/16 "2022-04-02T17:20:24Z")

</div>

> [@UnborN](#):
>
> `let ObjectId = mongodb.ObjectId`

Dear Unborn - arn't you from the Czech Republic? U sir, u deserve a beer or huge awesome coffee.... I spent a huge amount of time on this...

THANK YOU! 🙂

Jaroslav
