Access id from find() or findOne() result return an ObjectId not a string

Hi, I use Sveltekit with load function who need a stringifiable object for send data to the view.
Mongo query with nodejs adapter return a nested document full of ObjectId(string) value who cannot be stringified.

Cannot stringify arbitrary non-POJOs

How can I get a query result with string instead of ObjectId?
I have spend hours to try and find a solution without success.

The only way is to use JSON.parse and JSON.stringify everytime.

Hi @Axel_B and welcome to the MongoDB community forum!!

If I understand your concern correctly, you are looking an operator to convert the ObjectID returned from Find() and FindOne() query to return in the form of String and not ObjectID.

The documentation for Objectid.toString would be a good reference to start with.

Please let me know If my understanding is wrong here.
For better understanding, could you share some details like:

  1. Any sample code that you have tried to retrieve
  2. The complete error message you are seeing.

Regards
Aasawari