ObjectId Mongodb

#1

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)"

0 Likes

#2

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

0 Likes

#3

5bb0f4d4d7406a009bbcffef

0 Likes

#4

@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

0 Likes

#5

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....

0 Likes

#6

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

#7

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

1 Like