Get the App
SLTechnology News&Howtos  ›  Database  › 

MongoDB uses group by and displays other column max values

Shulou Source: shulou.com Published: 2022-06-01 22:45:04 09月15日 Update

The following script implements the function of duplicating the word_info table through the word field and writing it to the word_info_new table

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}))

Tags: Functions fields scripts tables Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Microsoft macOS Shulou Technology Redmi