# Node-red-contrib-mongodb4 handle document id error

**URL:** https://discourse.nodered.org/t/node-red-contrib-mongodb4-handle-document-id-error/75226
**Category:** General
**Created:** [15 February 2023 10:10 UTC](https://discourse.nodered.org/t/node-red-contrib-mongodb4-handle-document-id-error/75226 "2023-02-15T10:10:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bjdaijun](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bjdaijun/32/75846_2.png) [@bjdaijun](https://discourse.nodered.org/u/bjdaijun)
#### Post date: [15 February 2023 10:10 UTC](https://discourse.nodered.org/t/node-red-contrib-mongodb4-handle-document-id-error/75226/1 "2023-02-15T10:10:10Z")

</div>

As it docs says, it supports string id to ObjectId ,

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/6/061413f29611e367a6f5ca3e87be40167b16754e.png)

And as I use, the first is ok, that is [{\_id: "624b527d08e23628e99eb963"}]  
and the second usage: [{\_id: {$in: ["624b527d08e23628e99eb963"]}}], if the array only one items, It's also ok. but if the array has two or more items, only the fo item works.

For example:  
Here is my query:

```auto

var query={
    _id:{$in:["63ec78c7ee9d600c7c666a11","63e5fe8c029d12ec138189ab"]}
}
var update={
    $set:{
        isDeleted:1
    }
}
msg.payload=[query,update]
return msg;

```

And after some testing, It's only support one item in this array, and the mongo db operation works only for the first item. And other ids is leave not updated.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [15 February 2023 10:40 UTC](https://discourse.nodered.org/t/node-red-contrib-mongodb4-handle-document-id-error/75226/2 "2023-02-15T10:40:13Z")

</div>

Hi. Since this looks like a feature request for a contrib node, you will likely have to raise this with the author of that contrib node (link to repository will likely be in the nodes readme page on NPM) unless the author frequents this forum and sees your comment.

---

<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: [15 February 2023 22:26 UTC](https://discourse.nodered.org/t/node-red-contrib-mongodb4-handle-document-id-error/75226/3 "2023-02-15T22:26:15Z")

</div>

As a temporary workaround (until the node gets updated to support multiple ids)  
you can load the mongodb driver in your Function in order to convert to ObjectIds yourself

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

```auto
let ObjectId = mongodb.ObjectId

var query={
    _id:{$in:[ObjectId("63ec78c7ee9d600c7c666a11"),ObjectId("63e5fe8c029d12ec138189ab")]}
}
var update={
    $set:{
        isDeleted:1
    }
}
msg.payload=[query,update]
return msg;

```

---

<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: [1 March 2023 22:26 UTC](https://discourse.nodered.org/t/node-red-contrib-mongodb4-handle-document-id-error/75226/4 "2023-03-01T22:26:22Z")

</div>

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