I'm trying to figure out the best way to convert Object ID's that reference other collections to strings in a set of JSON data. It has to account for nested values. I am using a PHP back end and would like to convert them to strings before returning the data to the React front end.
Our React front end is set up to take the Object ID as a string when crawling through the data to render it, so we need to convert it from an Object ID.
// parentProduct is an ObjectId in the database, linking to a parentProduct collection
// and needs to be converted to a string in PHP when retrieving the JSON data.
{
"_id" : ObjectId("5b87fdb4a767e7c886730dbc"),
"name" : "My Sub-Product",
"parentProduct" : ObjectId("5063114bd386d8fadbd7a003")
}