Convert ObjectID (Mongodb) to String in JavaScript

后端 未结 16 1316
青春惊慌失措
青春惊慌失措 2020-12-02 19:50

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

16条回答
  •  一个人的身影
    2020-12-02 20:24

    Assuming the OP wants to get the hexadecimal string value of the ObjectId, using Mongo 2.2 or above, the valueOf() method returns the representation of the object as a hexadecimal string. This is also achieved with the str property.

    The link on anubiskong's post gives all the details, the danger here is to use a technique which has changed from older versions e.g. toString().

提交回复
热议问题