に参加しますV3.2にはいくつかの機能がありますが、これを行う能力は限られています。基本的には私が参加/スタックオーバーフロー上の次のポストごとに、2つのコレクションのマージをやろうとしているのMongoDB
私が下にしようとしていることを実行することが可能かどうか(例えば私が正しい道にいるか)、それができないかどうか教えてもらえますか?ここで
は私のコレクションです。ここで配分
{
"_id" : ObjectId("58a65c082c5fc49016c6a3cd"),
"data" : [
{
"version" : 0,
"jobTaskId" : {
"id" : 16089453
},
"endTime" : "2017-02-17T01:14:00.000+0000",
"minutes" : 210,
"trafficEmployeeId" : {
"id" : 3422
}
},
{
"version" : 1,
"jobTaskId" : {
"id" : 16089453
},
"endTime" : "2017-02-16T01:14:00.000+0000",
"minutes" : 400,
"trafficEmployeeId" : {
"id" : 3422
}
}
]
}
が私のコレクションです:従業
{
"_id" : ObjectId("58a66cc0c76ed0f7e9f52d0e"),
"data" : [
{
"version" : 67,
"userName" : "Jimjeff2",
"employeeDetails" : {
"id" : 3422,
"version" : 135
},
"personalDetails" : {
"id" : 24487,
"version" : 32,
"firstName" : "Jim",
"lastName" : "Jeffrey"
}
},
{
"version" : 37,
"userName" : "sandyub2",
"employeeDetails" : {
"id" : 3562,
"version" : 15
},
"personalDetails" : {
"id" : 24487,
"version" : 32,
"firstName" : "Sandy",
"lastName" : "Mason"
}
}
]
}
だから、私は、コレクション内の多くの割り当ての配列に一致するようにしようとしていますtrafficEmployeeId.idを対応する従業員のコレクションに使用employeeDetails.id
私はこの機能を使用しています:
db.allocations.find().forEach(
function (findAllocations) {
findAllocations.employees = db.employees.findOne({ "trafficEmployeeId.id": findAllocations.trafficEmployeeId.id });
findAllocations.allocations = db.allocations.find({ "employeeDetails.id": findAllocations.employeeDetails.id }).toArray();
db.allocationsReloaded.insert(findAllocations);
}
);
db.allocationsReloaded.find().pretty()
私は結果を返す取得しています:
TypeError: findAllocations.trafficEmployeeId is undefined :
@(shell):3:61
[email protected]/mongo/shell/query.js:477:1
@(shell):1:1