doupingtang9627 2018-10-12 09:59
浏览 67

MongoDB - 如何正确格式化PHP中的对象ID以用于React?

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")
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法