# MongoDB Out Node - Issues with \_id on Update

**URL:** https://discourse.nodered.org/t/mongodb-out-node-issues-with-id-on-update/6064
**Category:** General
**Created:** [22 December 2018 10:49 UTC](https://discourse.nodered.org/t/mongodb-out-node-issues-with-id-on-update/6064 "2018-12-22T10:49:05Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![SeanT](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@SeanT](https://discourse.nodered.org/u/SeanT)
#### Post date: [22 December 2018 10:49 UTC](https://discourse.nodered.org/t/mongodb-out-node-issues-with-id-on-update/6064/1 "2018-12-22T10:49:05Z")

</div>

Good Day,

I am attempting to do an update (overwrite) to MongoDB via the mongodb out node.

The notes suggest "... if you want repeated entries to overwrite, then you must set the `msg._id` property to be a constant by the use of a previous function node."

To test an INSERT, I set msg.\_id = 1111 in a function node and send that off with the payload and the record is correctly inserted into the db.

I then attempt to do a further INSERT, and get: "MongoError: E11000 duplicate key error collection: tempmdb.userConfig index: _id_ dup key: { : 1111 }".

So far so good, I'm happy the the key is working.

Then I change the mongodb node out operation to UPDATE, and I get: "TypeError: Cannot read property '\_id' of undefined".

What am I doing wrong?

Thanks in advance.

---

<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: [22 December 2018 11:12 UTC](https://discourse.nodered.org/t/mongodb-out-node-issues-with-id-on-update/6064/2 "2018-12-22T11:12:32Z")

</div>

which of the many mongo nodes are you using?

---

<div class="post-metadata">

### Author: ![SeanT](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@SeanT](https://discourse.nodered.org/u/SeanT)
#### Post date: [22 December 2018 11:17 UTC](https://discourse.nodered.org/t/mongodb-out-node-issues-with-id-on-update/6064/3 "2018-12-22T11:17:48Z")

</div>

node-red-node-mongodb

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/9655d7ac8ba6b0cace93c29b196075d1f14cd5c9.png)

---

<div class="post-metadata">

### Author: ![tizio](https://avatars.discourse-cdn.com/v4/letter/t/e9c0ed/32.png) [@tizio](https://discourse.nodered.org/u/tizio)
#### Post date: [17 January 2020 17:22 UTC](https://discourse.nodered.org/t/mongodb-out-node-issues-with-id-on-update/6064/4 "2020-01-17T17:22:41Z")

</div>

I have the same issue. Have you solved? if yes, how?

---

<div class="post-metadata">

### Author: ![SteveHiner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stevehiner/32/35537_2.png) [@SteveHiner](https://discourse.nodered.org/u/SteveHiner)
#### Post date: [18 January 2021 05:46 UTC](https://discourse.nodered.org/t/mongodb-out-node-issues-with-id-on-update/6064/5 "2021-01-18T05:46:45Z")

</div>

I ran into this same issue and found your post when trying to solve it. Then I looked at the docs for that node in Node-RED and found this:

> Update will modify an existing object or objects. The query to select objects to update uses `msg.query` and the update to the element uses `msg.payload` . If `msg.query._id` is a valid mongo ObjectId string it will be converted to an ObjectId type.

It appears you need to set msg.query.\_id when using Update but set msg.\_id when using Save.
