Aysennoussi
Aysennoussi

Reputation: 3860

Get the string inside objectId

I have mongoId like this :

ObjectId("53056c1e211b6f2e5d8b4567")

I only want

"53056c1e211b6f2e5d8b4567"

I tried toString but it returns the whole thing as string.
I know I can extract using string operations, but is there a native way to do so ?

Upvotes: 0

Views: 671

Answers (1)

jmen7070
jmen7070

Reputation: 626

You can do it:

ObjectId("53056c1e211b6f2e5d8b4567").valueOf()

it have to return the following string:

53056c1e211b6f2e5d8b4567

For more details, see docs

Upvotes: 2

Related Questions