# Objectid is not compatible with my version of node

**URL:** <https://discourse.nodered.org/t/objectid-is-not-compatible-with-my-version-of-node/49467>\
**Category:** General\
**Created:** [8 August 2021 03:02 UTC](https://discourse.nodered.org/t/objectid-is-not-compatible-with-my-version-of-node/49467 "2021-08-08T03:02:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrSidX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrsidx/32/18935_2.png) [@mrSidX](https://discourse.nodered.org/u/mrSidX)\
**Post date:** [8 August 2021 03:02 UTC](https://discourse.nodered.org/t/objectid-is-not-compatible-with-my-version-of-node/49467/1 "2021-08-08T03:02:47Z")

</div>

Trying to migrate to new server, and when I did, I upgraded node-red to version 2.0.5, and now I am having some major issues.

Flows won't deploy due to missing node types, and I keep getting errors installing some nodes:

```auto
2021-08-08T02:57:09.697Z Install : node-red-contrib-objectid 0.7.2

2021-08-08T02:57:11.434Z npm install --no-audit --no-update-notifier --no-fund --save --save-prefix=~ --production --engine-strict node-red-contrib-objectid@0.7.2
2021-08-08T02:57:13.142Z [err] npm
2021-08-08T02:57:13.143Z [err]  
2021-08-08T02:57:13.143Z [err] WARN
2021-08-08T02:57:13.143Z [err]  
2021-08-08T02:57:13.143Z [err] old lockfile
2021-08-08T02:57:13.143Z [err]  
2021-08-08T02:57:13.143Z [err] npm
2021-08-08T02:57:13.143Z [err]  
2021-08-08T02:57:13.143Z [err] WARN
2021-08-08T02:57:13.143Z [err]  
2021-08-08T02:57:13.146Z [err] old lockfile
2021-08-08T02:57:13.146Z [err] The package-lock.json file was created with an old version of npm,
2021-08-08T02:57:13.146Z [err] npm
2021-08-08T02:57:13.146Z [err]  
2021-08-08T02:57:13.146Z [err] WARN
2021-08-08T02:57:13.146Z [err]  
2021-08-08T02:57:13.146Z [err] old lockfile
2021-08-08T02:57:13.146Z [err] so supplemental metadata must be fetched from the registry.
2021-08-08T02:57:13.146Z [err] npm
2021-08-08T02:57:13.146Z [err]  
2021-08-08T02:57:13.146Z [err] WARN
2021-08-08T02:57:13.146Z [err]  
2021-08-08T02:57:13.147Z [err] old lockfile
2021-08-08T02:57:13.147Z [err]  
2021-08-08T02:57:13.147Z [err] npm
2021-08-08T02:57:13.147Z [err]  
2021-08-08T02:57:13.147Z [err] WARN
2021-08-08T02:57:13.147Z [err]  
2021-08-08T02:57:13.147Z [err] old lockfile
2021-08-08T02:57:13.147Z [err] This is a one-time fix-up, please be patient...
2021-08-08T02:57:13.147Z [err] npm
2021-08-08T02:57:13.147Z [err]  
2021-08-08T02:57:13.147Z [err] WARN
2021-08-08T02:57:13.147Z [err]  
2021-08-08T02:57:13.147Z [err] old lockfile
2021-08-08T02:57:13.152Z [err]  
2021-08-08T02:57:54.253Z [err] npm
2021-08-08T02:57:54.254Z [err]  
2021-08-08T02:57:54.254Z [err] ERR!
2021-08-08T02:57:54.254Z [err]  
2021-08-08T02:57:54.254Z [err] code
2021-08-08T02:57:54.254Z [err] EBADENGINE
2021-08-08T02:57:54.256Z [err] npm
2021-08-08T02:57:54.256Z [err]  
2021-08-08T02:57:54.256Z [err] ERR!
2021-08-08T02:57:54.256Z [err]  
2021-08-08T02:57:54.256Z [err] engine
2021-08-08T02:57:54.256Z [err] Unsupported engine
2021-08-08T02:57:54.256Z [err] npm
2021-08-08T02:57:54.256Z [err]  
2021-08-08T02:57:54.256Z [err] ERR!
2021-08-08T02:57:54.256Z [err]  
2021-08-08T02:57:54.256Z [err] engine
2021-08-08T02:57:54.256Z [err] Not compatible with your version of node/npm: node-red-contrib-objectid@0.7.2
2021-08-08T02:57:54.257Z [err] npm
2021-08-08T02:57:54.257Z [err]  
2021-08-08T02:57:54.257Z [err] ERR!
2021-08-08T02:57:54.257Z [err]  
2021-08-08T02:57:54.257Z [err] notsup
2021-08-08T02:57:54.257Z [err] Not compatible with your version of node/npm: node-red-contrib-objectid@0.7.2
2021-08-08T02:57:54.257Z [err] npm
2021-08-08T02:57:54.257Z [err]  
2021-08-08T02:57:54.257Z [err] ERR!
2021-08-08T02:57:54.257Z [err]  
2021-08-08T02:57:54.257Z [err] notsup
2021-08-08T02:57:54.257Z [err] Required: {"node":"^0.12.7"}
2021-08-08T02:57:54.257Z [err] npm
2021-08-08T02:57:54.257Z [err]  
2021-08-08T02:57:54.257Z [err] ERR!
2021-08-08T02:57:54.257Z [err]  
2021-08-08T02:57:54.258Z [err] notsup
2021-08-08T02:57:54.258Z [err] Actual: {"npm":"7.20.3","node":"v16.6.1"}
2021-08-08T02:57:54.271Z [err] 
2021-08-08T02:57:54.271Z [err] npm
2021-08-08T02:57:54.271Z [err]  
2021-08-08T02:57:54.271Z [err] ERR!
2021-08-08T02:57:54.271Z [err] A complete log of this run can be found in:
2021-08-08T02:57:54.271Z [err] npm
2021-08-08T02:57:54.272Z [err]  
2021-08-08T02:57:54.272Z [err] ERR!
2021-08-08T02:57:54.272Z [err] /home/sidthetech/.npm/_logs/2021-08-08T02_57_54_260Z-debug.log
2021-08-08T02:57:54.281Z rc=1

```

I am using node version 16.x.x and I understand that the node probably won't work on the new version. This was used in my old flows when querying mongodb ...

I really want to use the latest version of node-red and hopefully node.

Any suggestions to get this going? I imagine there are other node types that are probably outdated as well.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [8 August 2021 07:37 UTC](https://discourse.nodered.org/t/objectid-is-not-compatible-with-my-version-of-node/49467/2 "2021-08-08T07:37:41Z")

</div>

You would need to contact the author of that node to see if they are willing to update it. Or stop using it.

---

<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:** [8 August 2021 07:45 UTC](https://discourse.nodered.org/t/objectid-is-not-compatible-with-my-version-of-node/49467/3 "2021-08-08T07:45:50Z")

</div>

Maybe this fork will work?

> **[node-red-contrib-bson](https://flows.nodered.org/node/node-red-contrib-bson)**
>
> Node Red Node to create an ObjectID for mongodb.

---

<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:** [8 August 2021 09:26 UTC](https://discourse.nodered.org/t/objectid-is-not-compatible-with-my-version-of-node/49467/4 "2021-08-08T09:26:16Z")

</div>

@mrSidX im guessing you were using that `node-red-contrib-objectid` because somewhere in your flow you are using a Function node to prepare a query for the Mongodb database? and you wanted to query based on the \_id and the id in mongo is a special object which is not exposed to Function nodes. Is this correct ?

maybe there is a way around it without using a seperate node just to create that ObjectId.

with the new versions of Node-red you have something called `functionExternalModules` that gives you the ability to load external modules in your Function nodes. You can read how to set that up [here](https://nodered.org/docs/user-guide/writing-functions#using-the-functionexternalmodules-option)

Now with that setup you can use the mongodb driver module in the Setup tab of your Function node.

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

and in code you can use mongo's ObjectId like this `ObjectId("6001215079d9790bac657abb")`  
below is just an example of my temperatures collection test db

```javascript
let ObjectId = mongodb.ObjectId

msg.collection = "temperatures"
msg.operation = "aggregate"

msg.payload = [
   //{$unwind: "$temps"},
   { "$match": { "_id": ObjectId("6001215079d9790bac657abb") } },
   { "$sort": { dt: -1 } },
   //{"$limit": 2},
   //{"$skip": 0}
];

return msg;

```

---

<div class="post-metadata">

**Author:** ![mrSidX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrsidx/32/18935_2.png) [@mrSidX](https://discourse.nodered.org/u/mrSidX)\
**Post date:** [8 August 2021 20:15 UTC](https://discourse.nodered.org/t/objectid-is-not-compatible-with-my-version-of-node/49467/5 "2021-08-08T20:15:50Z")

</div>

You are absolutely 100% on point.

I have many end-points/flows to modify in this case, and  
I foresee a few works arounds...

-Implement the `functionExternalModules` as you suggest to have the Mongo Object accessible to the function node, and hand change all the endpoints/flows in function code to accommodate this work-around,

-Do the said work-around above, but have a Universal SubFlow that will act like the existing `objectid`

-Or : Just modify the `objectid` node to be compatible with the new node versions. (ideal for my case)

Wondering how involved it might be to update the node-type to something similar that will work.  
Maybe I can contact the developer?  
Maybe I can modify the existing package to play nice?

I'm not a deep node-red-node developer by any means, so maybe the work-around will have to suffice.

---

<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:** [8 August 2021 21:05 UTC](https://discourse.nodered.org/t/objectid-is-not-compatible-with-my-version-of-node/49467/6 "2021-08-08T21:05:17Z")

</div>

when you say

> [@mrSidX](#):
>
> I have many end-points

how many are there ? 😉  
its going to be a hassle to change all the functions and the `functionExternalModules` workaround needs a couple of steps but at least you wont be depended on a node for something simple, since you are already using a function before your db. Its up to you.

By the way i tried installing both nodes also on my system (node v14) and both fail and require a 5 year old nodejs. The github link of `node-red-contrib-objectid` is dead and the package deprecated so i dont know how easy it is to contact the developer.

---

<div class="post-metadata">

**Author:** ![mrSidX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrsidx/32/18935_2.png) [@mrSidX](https://discourse.nodered.org/u/mrSidX)\
**Post date:** [8 August 2021 21:16 UTC](https://discourse.nodered.org/t/objectid-is-not-compatible-with-my-version-of-node/49467/7 "2021-08-08T21:16:13Z")

</div>

> [@UnborN](#):
>
> ts going to b

agreed... There are quite a few endpoints to modify, as I have a user system built in, utilizing the database, and various other flows that query with the DB  
I have a "middleware" type of Subflow where every endpoint visited gets client token/session and queries the db for that associated user, checks if it's a valid user, and returns what permissions and other user related data.

---

<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:** [8 August 2021 21:38 UTC](https://discourse.nodered.org/t/objectid-is-not-compatible-with-my-version-of-node/49467/8 "2021-08-08T21:38:33Z")

</div>

so what exactly were you passing into the `node-red-contrib-objectid` ?  
what was the msg like ?

according to the node's [page](https://flows.nodered.org/node/node-red-contrib-objectid)  
you needed the string \_id to be either  
`msg.payload._id = "572dbc06f307c8682045c55c"`  
or  
`msg.payload.uuid = "572dbc06f307c8682045c55c"`

Create a function that with the use of `functionExternalModules` replicates what `node-red-contrib-objectid` did.

for Example

```auto
let ObjectId = mongodb.ObjectId

try {
    msg.payload._id = ObjectId(msg.payload._id)
    return msg;
} catch (error) {
    node.warn(error);
};

```

and copy paste and replace all object id nodes with your own function node  
try it on one endpoint first for test

---

<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 October 2021 21:38 UTC](https://discourse.nodered.org/t/objectid-is-not-compatible-with-my-version-of-node/49467/9 "2021-10-07T21:38:52Z")

</div>

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