Question: 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 string.

Answer: 
in the [shell](https://docs.mongodb.com/manual/reference/method/ObjectId/)

`ObjectId("507f191e810c19729de860ea").str`

in js [using the native driver for node](http://mongodb.github.io/node-mongodb-native/2.0/api/ObjectID.html)

`objectId.toHexString()`
Found this really funny but it worked for me:

```
    db.my_collection.find({}).forEach((elm)=>{

    let value = new String(elm.USERid);//gets the string version of the ObjectId which in turn changes the datatype to a string.

    let result = value.split("(")[1].split(")")[0].replace(/^"(.*)"$/, '$1');//this removes the objectid completely and the quote 
    delete elm["USERid"]
    elm.USERid = result
    db.my_collection.save(elm)
    })

```