我有一个包含这样文件的集合:
{"_id" : {
"SpId" : 250,
"Channel_Id" : 2,
"TweetId" : 1
},
"Sentiment" : -0.83,
"AgeGroup" : "13-17",
"Gender" : "F",
"Location" : {
"Country" : "Russia",
"Lat" : "46.7323875",
"Long" : "-117.0001651",
"City" : "Moscow"
},
"IdeaCloudText" : " PS_realized PS_have PS_enough NG_drunk"
}
{"_id" : {
"SpId" : 250,
"Channel_Id" : 2,
"TweetId" : 2
},
"Sentiment" : -0.70,
"AgeGroup" : "21-40",
"Gender" : "F",
"Location" : {
"Country" : "United States",
"Lat" : "25.4791234",
"Long" : "-142.0001651",
"City" : "LA"
},
"IdeaCloudText" : " PS_good NG_dangerous"
}
虽然我对该要求的性能可行性感到担忧,但我必须生成这样的输出:
{"_id" : {
"SpId" : 250,
"Channel_Id" : 2,
},
"IdeaCloudTextFinal" : "PS_realized PS_have PS_enough NG_drunk PS_good NG_dangerous"
}
此处,每个文档的 IdeaCloudText 值在单个输出文档中的单个键 IdeaCloudTextFinal 中连接。
我读到了concat运算符但不确定它在这种情况下是否有用(我怀疑甚至需要聚合框架);我试图(当然有错误)这样的事情:
db.Twitter_Processed.aggregate({$match : { "_id.SpId":250}}, {$project : { SpId : "$_id.SpId", IdeaCloudText : "$IdeaCloudText"}}, /*HOW TO CONCATENATE*/)
如何实现此连接?任何性能影响指针和/或更好的方法都是受欢迎的。