I want to convert ObjectID (Mongodb) to String in JavaScript. When I get a Object form MongoDB. it like as a object has: timestamp, second, inc, machine. I can\'t convert to
Use toString:
var stringId = objectId.toString()
Works with the latest Node MongoDB Native driver (v3.0+):
http://mongodb.github.io/node-mongodb-native/3.0/
You can use string formatting.
const stringId = `${objectId}`;
Try this:
objectId.str
See the doc.
ObjectId()
has the following attribute and methods:[...]
str
- Returns the hexadecimal string representation of the object.
Just use this : _id.$oid
And you get the ObjectId string. This come with the object.