我一直在嘗試在MongoDB中使用MapReduce來做我認為簡單的過程。我不知道這是否是正確的方法,甚至不應該使用MapReduce。我用谷歌搜索了我想到的關鍵詞,并試圖在文檔中找到我認為最成功的文檔,但是沒有結果。也許我在想這個嗎?我有兩個收藏夾:details和gpasdetails由一堆文件(3+百萬個)組成。所述studentid元件可以被重復兩次,每個year,如下所示:{ "_id" : ObjectId("4d49b7yah5b6d8372v640100"), "classes" : [1,17,19,21], "studentid" : "12345a", "year" : 1}{ "_id" : ObjectId("4d76b7oij7s2d8372v640100"), "classes" : [2,12,19,22], "studentid" : "98765a", "year" : 1}{ "_id" : ObjectId("4d49b7oij7s2d8372v640100"), "classes" : [32,91,101,217], "studentid" : "12345a", "year" : 2}{ "_id" : ObjectId("4d76b7rty7s2d8372v640100"), "classes" : [1,11,18,22], "studentid" : "24680a", "year" : 1}{ "_id" : ObjectId("4d49b7oij7s2d8856v640100"), "classes" : [32,99,110,215], "studentid" : "98765a", "year" : 2}...gpas具有與相同studentid的元素details。每個僅一個條目studentid,如下所示:{ "_id" : ObjectId("4d49b7yah5b6d8372v640111"), "studentid" : "12345a", "overall" : 97, "subscore": 1}{ "_id" : ObjectId("4f76b7oij7s2d8372v640213"), "studentid" : "98765a", "overall" : 85, "subscore": 5}{ "_id" : ObjectId("4j49b7oij7s2d8372v640871"), "studentid" : "24680a", "overall" : 76, "subscore": 2}...但是,當我運行它時,這是我得到的集合:{ "_id" : "12345a", "value" : { "studentid" : "12345a", "classes_1" : [ ], "classes_2" : [ ], "overall" : 97, "subscore" : 1 } }{ "_id" : "98765a", "value" : { "studentid" : "98765a", "classes_1" : [ ], "classes_2" : [ ], "overall" : 85, "subscore" : 5 } }{ "_id" : "24680a", "value" : { "studentid" : "24680a", "classes_1" : [ ], "classes_2" : [ ], "overall" : 76, "subscore" : 2 } }我想念的類數組。另外,順便說一句,如何訪問生成的MapReduce value元素中的元素?MapReduce總是輸出到value還是您將其命名為其他名稱?
2 回答

qq_花開花謝_0
TA貢獻1835條經驗 獲得超7個贊
您不能為此使用m / r,因為它僅設計用于一個集合。從多個集合中讀取將破壞分片兼容性,因此不允許這樣做。您可以使用新的聚合框架(2.1+)或在應用程序內部執行所需的操作。
- 2 回答
- 0 關注
- 1415 瀏覽
添加回答
舉報
0/150
提交
取消