2
votes

Is it possible to stringify a field in a collection declared as an ObjectId type via Mongoose Schema? I expected .lean() to do this, but it seems I'm still getting back ObjectId. I suppose what I want is query return to JSON conversion. Is that doable in a single Mongoose query? If not, how would I manually convert all ObjectId types in a nested document?

1

1 Answers

0
votes

I don't know if you still have this question, though I found your question because I had the same problem.

Here's what I found per the mongodb docs:

ObjectId("hexID").valueOf() will return a string of the hex ID.