I need to be able to obtain only the string that makes up the Id in a query to MongoDB

Viewed 28

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 ObjectId

async findById(id:string) {
    const convert = {"_id":id}
    const userfindById = await userModel.findById(convert);
    const iD = userfindById?._id
    return userfindById;
}
1 Answers
Related