我的文档曾经是这样的:
{
_id : 47cc67093475061e3d95369d,
Name : "A name",
Description : "Some description",
DisciplineCode : "105",
DisciplineName : "A Name",
OtherProperty : "Something"
}
为此,以下组命令起作用,以便从我的文档中获取不同的 DisciplineNames 和 DisciplineCodes
disciplines = db.result.group({
key: {DisciplineName:1, DisciplineCode:1},
reduce: function(obj, prev) { if (!obj.hasOwnProperty("DisciplineName")) {
prev.DisciplineName = obj.DisciplineName;
prev.DisciplineCode = obj.DisciplineCode;
}},
initial: { }
});
但是,我的文档现在已更改为:
{
_id : 47cc67093475061e3d95369d,
Name : "A name",
Description : "Some description",
Discipline: {
Code : "105",
Name : "A Name"},
OtherProperty : "Something"
}
如您所见,Discipline
是一个嵌入式文档。
如何修改我的组命令以仍然执行相同的操作?