Cannot convert ObjectId to hexadecimal string

huhamhire shared this problem 6 years ago
Solved

I have tried all these methods

ObjectId().str
ObjectId().String()
ObjectId().valueOf()
_.toString(ObjectId())
But I couldn't find one way to get the hexadecimal string of ObjectId. Both ObjectId().str and ObjectId.valueOf() works in mongoshell, and they don't work in NoSqlBooster.

Replies (1)

photo
2

Which version are you using? If you are using 4.5.1 and below,


please use "ObjectID.toHexString()" as a work around solution.

let id=new ObjectID();


id. toHexString ();

//return 5ab8b40d4b8a25a8ccde6ae0

Or, you can download 4.5.2 manually, and use "ObjectId().valueOf()"

https://nosqlbooster.com/downloads

photo
1

I was using 4.5.1. I've tried upgrade to 4.5.2, and problem solved.

Thanks.🙂

photo
Leave a Comment
 
Attach a file