【发布时间】:2018-03-12 19:27:27
【问题描述】:
我在下面的表格中有数据
{
"_id" : ObjectId("5a9d1b70b826170df4365489"),
"userId" : "5a93e0b76d32cd0e6c1b99aa",
"mediaId" : "5a99330af218d30c981cda2f",
"comment" : "Hi this is a video",
"**replies**" : [
{
"comment" : "this is a reply 1",
"**userId**" : "5a93e0b76d32cd0e6c1b99aa"
},
{
"comment" : "this is a reply 2",
"**userId**" : "5a93e0b76d32cd0e6c1b99aa"
},
{
"comment" : "this is a reply 3",
"**userId**" : "5a93e0b76d32cd0e6c1b99aa"
}
],
"createdAt" : "",
"updatedAt" : ""
}
我的问题: 如何在回送中回复数组的每个对象中为 userId 设置关系并包含来自 用户表 的数据?
我的预期输出:
{
"_id" : ObjectId("5a9d1b70b826170df4365489"),
"userId" : "5a93e0b76d32cd0e6c1b99aa",
"mediaId" : "5a99330af218d30c981cda2f",
"comment" : "Hi this is a video",
"**replies**" : [
{
"comment" : "this is a reply 1",
"**userId**" : "5a93e0b76d32cd0e6c1b99aa",
"userDetails":{
"name":"xxxxxxxxx",
"address":"xxxxxxxx"
}
},
{
"comment" : "this is a reply 2",
"**userId**" : "5a93e0b76d32cd0e6c1b99aa",
"userDetails":{
"name":"xxxxxxxxx",
"address":"xxxxxxxx"
}
},
{
"comment" : "this is a reply 3",
"**userId**" : "5a93e0b76d32cd0e6c1b99aa",
"userDetails":{
"name":"xxxxxxxxx",
"address":"xxxxxxxx"
}
}
],
"createdAt" : "",
"updatedAt" : ""
}
我在这里卡住了。请分享一些解决方案
【问题讨论】:
标签: loopbackjs strongloop