Categories
JavaScript Answers

How to convert MongoDB ObjectID to string in JavaScript?

Spread the love

Sometimes, we want to convert MongoDB ObjectID to string in JavaScript.

In this article, we’ll look at how to convert MongoDB ObjectID to string in JavaScript.

How to convert MongoDB ObjectID to string in JavaScript?

To convert MongoDB ObjectID to string in JavaScript, we use the str property.

For instance, we write

const s = ObjectId("507f191e810c19729de860ea").str;

to create an object ID with ObjectId.

Then we get the string content of the object ID with str.

Conclusion

To convert MongoDB ObjectID to string in JavaScript, we use the str property.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.