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.