MongoDB 使用group by 并显示其他列max值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
                                    
                                )
    );

以上是关于MongoDB 使用group by 并显示其他列max值的主要内容,如果未能解决你的问题,请参考以下文章