MongoDB 使用group by 並顯示其他列max值

以下腳本實現功能爲把word_info表通過word字段去重,並寫到到word_info_new表裏

db.word_info.aggregate([
{$group:
        { _id:"$word" ,
         meaning:{$max:"$meaning"}, 
         usphonetic:{$max:"$usphonetic"} 
        }
 }]).forEach(
            function(dc){
                    db.word_info_new.insert(
                                    {"word":dc._id,
                                        "meaning":dc.meaning,
                                        "usphonetic":dc.usphonetic
                                    }
                                )}
    );
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章