Convert ObjectID (Mongodb) to String in JavaScript

后端 未结 16 1315
青春惊慌失措
青春惊慌失措 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:34

    In Js do simply: _id.toString()

    For example:

    const myMongoDbObjId = ObjectID('someId');
    const strId = myMongoDbObjId.toString();
    console.log(typeof strId); // string
    

提交回复
热议问题