我的文檔用於這個樣子的:嵌入文檔中使用的MongoDB集團
{
_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
是一個嵌入式文檔。
我該如何修改我的組命令仍然執行相同的操作?
燦你確認你的減少功能是正確的?如果obj沒有「disciplineName」字段,請將以前文檔的名稱字段設置爲不存在的值? – Jenna 2012-07-10 21:02:49