Question:
I’m using mongoDB, mongoose and typescript and I need to keep the document ids when I query but I can only get the type _id: new ObjectId(“62aa4bddae588fb13e8df552”) . I only need to keep the string “62aa4bddae588fb13e8df552” to later store it and do other processing. I can’t get rid of the new ObjectIdAnswer:
ObjectId is just a type :https://www.mongodb.com/docs/manual/reference/bson-types/#std-label-objectid
If you want to get the string you can extract with
_id.toString()
, if you want to store the string you should change the type of _id
(or create a new property)If you have better answer, please add a comment about this, thank you!