计算mongodb中所有文档中字符串数组中字符串的出现次数

时间:2017-11-18 14:59:43

标签: mongodb

我的数据库(数据)中的所有文档都有一个tags_data:

tags_data : [ "am", "gi", "bab", "as", "bru", "dan", "tea", "wec", "fuy" ]

所以我想对所有标签的概述与每个标签的出现次数进行排序,如果可能的话,按降序排序

我想尝试这样做:

db.data.aggregate(
    {$unwind: '$tags_data'},
    {$group: {_id: '$tags_data', sum: {$sum: +1}}}
);

谢谢和问候

1 个答案:

答案 0 :(得分:0)

答案是:

SELECT smf_user_points_log.id_member, smf_members.usertitle
    FROM smf_user_points_log
    INNER JOIN smf_members
    ON smf_members.id_member=smf_user_points_log.id_member
    WHERE smf_user_points_log.id_school_year = (SELECT id_school_year FROM smf_settings) AND smf_user_points_log.points >= 50 AND smf_members.date_registered < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY))

感谢