我有两个收藏奖团队赢得了团队列表。我想将整个奖项作为子文档进行 ETL 到其他(团队)中,并进行一些小的转换,但我只从奖项中获得一个子文档到团队中。
这是我使用的代码。Teams 有一个唯一的数字索引,看起来像最终文档减去 accolade 子文档。但是,数组中只添加了一个 accolade 子文档。我错过了什么?
db.awardout.find().forEach(function(award_team){
if(award_team != null)
{
db.teams.findAndModify(
{
query: {number: award_team.team},
update: { $set: {accolades: [ {sku: award_team.sku, acc_category: "Award", acc_name: award_team.name }] } },
upsert: true,
});
}
});
示例奖项(团队可以赢得多个奖项,荣誉是奖项的集合,以便以后汇总):
/* 18 */
{
"_id" : ObjectId("552077289ad9c19e809965de"),
"sku" : "RE-VRC-14-0110",
"name" : "Tournament Finalists (VRC/VEXU)",
"team" : "44",
"qualifies" : [],
"order" : "1"
}
/* 35 */
{
"_id" : ObjectId("552077289ad9c19e809965ef"),
"sku" : "RE-VRC-14-0110",
"name" : "Robot Skills Winner (VRC/VEXU)",
"team" : "44",
"qualifies" : [],
"order" : "4"
}
以下是仅添加一项荣誉的团队变成的样子:
{
"_id" : ObjectId("552071f69ad9c19e80996432"),
"program" : "VRC",
"robot_name" : "Fred VII",
"organisation" : "Green Egg Robotics",
"region" : "Massachusetts",
"country" : "United States",
"number" : "44",
"team_name" : "Green Egg Robotics",
"city" : "Oakham",
"grade" : "High School",
"is_registered" : "0",
"accolades" : [{
"sku" : "RE-VRC-14-0110",
"acc_category" : "Award",
"acc_name" : "Think Award (VRC/VEXU)"
}]
}
我本来希望将两个荣誉添加到数组中。我是否需要将奖励对象 ID 携带到团队子文档中?