ObjectId Mongodb


Hi guys,

I have inserted a few datasets into my mongodb. Worked fine with my "mongodb3" Node.

Now I want to query one single data object, and I have the _id of this object. Nevertheless I am not able to get it in the result set (find.toArray):

msg.payload = { "_id": ObjectId("5bb0f4d4d7406a009bbcffef") } as well as without "ObjectId" it is not working.

--> "ReferenceError: ObjectId is not defined (line 1, col 95)"



well is the id ObjectId("5bb0f4d4d7406a009bbcffef") or is it 5bb0f4d4d7406a009bbcffef?






@zenofmud The Mongo API provides a custom object called ObjectId to use. Unfortunately it is a pain to use with Node-RED as no other nodes know about it.

@number005 I'm afraid I don't have a quick solution here - its been ages since I've used mongo, but I do know others have stumbled over this in the past. You may want to search the old mailing list for any tips - https://groups.google.com/forum/#!forum/node-red



I already had a look there before, but didn't find a good solution. Somehow I should modify the node-red source code, to make the ObjectId() available. But I am not a huge pro....



I stumbled on the same problem described here, opted to generate my own string IDs. Otherwise, you may want to look at what node-red-contrib-objectid is doing.

1 Like


I had to use node-red-contrib-objectid to make it work.

1 Like