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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *