我有两个名为ServiceProvider和Parents的集合。
的ServiceProvider:
{
"_id" : ObjectId("57235dc9588aec3e318b4567"),
"ServiceProviderID" : 3,
"Title" : "test",
"PostedMessage" : "test",
"TotalComments" : 0,
"TotalShares" : 0,
"TotalThanks" : 0,
"AddedOn" : "2016-04-29",
"LastModifiedOn" : "2016-04-29",
"PostAttachment" : {
"ImagePath" : ""
},
"PostComments" : [
{
"_id" : "14619355772980176",
"UserID" : 3,
"CommentMessage" : "test",
"TotalThanks" : 0,
"AddedOn" : "2016-04-29",
"LastModifiedOn" : "2016-04-29",
"CommentAttachment" : {
"ImagePath" : ""
}
},
{
"_id" : "1461935582156657330",
"UserID" : 3,
"CommentMessage" : "123",
"TotalThanks" : 0,
"AddedOn" : "2016-04-29",
"LastModifiedOn" : "2016-04-29",
"CommentAttachment" : {
"ImagePath" : ""
}
},
{
"_id" : "14619892452027996767",
"UserID" : 3,
"CommentMessage" : "45",
"TotalThanks" : 0,
"AddedOn" : "2016-04-30",
"LastModifiedOn" : "2016-04-30",
"CommentAttachment" : {
"ImagePath" : ""
}
},
{
"_id" : "14619896331049580283",
"UserID" : 3,
"CommentMessage" : "46",
"TotalThanks" : 0,
"AddedOn" : "2016-04-30",
"LastModifiedOn" : "2016-04-30",
"CommentAttachment" : {
"ImagePath" : ""
}
}
],
"Subscriber" : [ ]
}
父母:
{
"35" : {
"ID" : "133",
"UID" : "7Cv1y3kjutSWgvhtH1Lp9yEDOeiFR0aAbB77uTnEJCR3HSH0s6eC7rEt",
"Name" : "Ash Nan",
"ProfileImagePath" : null
},
"36" : {
"ID" : "134",
"UID" : "2BRcj3xBnNzse7YiudouwmYprilzjkbrC4Yk7v9gPBcs6eC7rEt",
"Name" : "Test 45",
"ProfileImagePath" : "Chrysanthemum_134_1450777239#SIZE#.jpg"
},
"37" : {
"ID" : "135",
"UID" : "BCMMdFjfO7WXzESWQ8Wlnge4gMQoumBxXyY99NIou5UzKrRgs6eC7rEt",
"Name" : "test 45",
"ProfileImagePath" : "Penguins_135_1450777743#SIZE#.jpg"
},
"38" : {
"ID" : "136",
"UID" : "HxFmh7T4balaAbB77UTEgJtrxXyY99zCUEYeaAbB77SF11rKv8ad9FS6Tss6eC7rEt",
"Name" : "test1 test1",
"ProfileImagePath" : null
},
}
如何使用Parents集合对Postcomments子文档执行查询查询?
我想将来自Parents集合的Name
字段插入ServiceProvider Postcomments子文档中。
我希望查询返回以下内容:
{
"_id" : ObjectId("57235dc9588aec3e318b4567"),
"ServiceProviderID" : 3,
"Title" : "test",
"PostedMessage" : "test",
"TotalComments" : 0,
"TotalShares" : 0,
"TotalThanks" : 0,
"AddedOn" : "2016-04-29",
"LastModifiedOn" : "2016-04-29",
"PostAttachment" : {
"ImagePath" : ""
},
"PostComments" : [
{
"_id" : "14619355772980176",
"UserID" : 3,
"UserName" : "Chinmay Kulkarni",
"CommentMessage" : "test",
"TotalThanks" : 0,
"AddedOn" : "2016-04-29",
"LastModifiedOn" : "2016-04-29",
"CommentAttachment" : {
"ImagePath" : ""
}
},
{
"_id" : "1461935582156657330",
"UserID" : 3,
"UserName" : "Chinmay Kulkarni",
"CommentMessage" : "123",
"TotalThanks" : 0,
"AddedOn" : "2016-04-29",
"LastModifiedOn" : "2016-04-29",
"CommentAttachment" : {
"ImagePath" : ""
}
},
{
"_id" : "14619892452027996767",
"UserID" : 3,
"UserName" : "Chinmay Kulkarni",
"CommentMessage" : "45",
"TotalThanks" : 0,
"AddedOn" : "2016-04-30",
"LastModifiedOn" : "2016-04-30",
"CommentAttachment" : {
"ImagePath" : ""
}
},
{
"_id" : "14619896331049580283",
"UserID" : 3,
"UserName" : "Chinmay Kulkarni",
"CommentMessage" : "46",
"TotalThanks" : 0,
"AddedOn" : "2016-04-30",
"LastModifiedOn" : "2016-04-30",
"CommentAttachment" : {
"ImagePath" : ""
}
}
],
"Subscriber" : [ ]
}
我指的是this链接,但没有通过。任何帮助,将不胜感激。谢谢!