How create a valid ObjectID in mongodb

Hello!,

How can I create a valid ObjectID to save this in mong

odb ?
I need something like this

the red one is what I need, and the green is what I get :

red : _id : ObjectId(“xxxxxxxxxxxxx”)

green : _id : Object
oid : null

I need the id to be generated as mongo does and not created by me, I was trying this :

thanks!

I find this solution,

add library js-bson

image

then use it like moment, uuid , lodash, etc

image

1 Like

Hello @sergio_fpay!

Great to hear you found a solution.

As long as the ID just needs to be unique that should work well!