查询集合和提取关键字的数量,并排序哪个文档的总数最高

时间:2016-10-19 18:26:19

标签: mongodb count keyword

我有一个如下所示的集合。我想查询具有最多关键字的名称(我指定的名称,例如优秀,优秀等)。

{ 
    "_id" : ObjectId("561c3ccc4c97f053753f1a78"), 
    "Reviews" : 
    [
        {
        "Ratings" : {
                     "Service" : "4", 
                     "Overall" : "5"
                    }, 
        "Location" : "MIS", 
        "Title" : "“Excellent and great”", 
        "Author" : "JDoe", 
        "ReviewID" : "1", 
        "Date" : "March 30, 2015"
        }, 
       {
        "Ratings" : {
                      "Service" : "4", 
                      "Overall" : "5"  
                     }, 
        "Location" : "WIS", 
        "Title" : "“Excellent and fantastic!”", 
        "Author" : "John Doe", 
        "ReviewID" : "2",  
        "Date" : "March 27, 2016"
       }
    ],

    "Info" : 
    {
    "Name" : "AA",
    "ID" : "0001"
     }
}

{ 
    "_id" : ObjectId("561c3ccc4c97f0ytu7289074"), 
    "Reviews" : 
    [
        {
        "Ratings" : {
                     "Service" : "4", 
                     "Overall" : "5"
                    }, 
        "Location" : "VEG", 
        "Title" : "“Not too bad”", 
        "Author" : "JDoe", 
        "ReviewID" : "3", 
        "Date" : "March 30, 2015"
        }, 
       {
        "Ratings" : {
                      "Service" : "4", 
                      "Overall" : "5"  
                     }, 
        "Location" : "NEV", 
        "Title" : "“Outstanding service”", 
        "Author" : "John Doe", 
        "ReviewID" : "4",  
        "Date" : "March 27, 2016"
       }
    ],

    "Info" : 
    {
      "Name" : "BB",
      "ID" : "0002"
     }
}

标题中过滤器的关键字:" oustanding","伟大","太棒了"

预期产出:

" AA":总计:4优秀:2优秀:1太棒了:1 " BB":总计:1优秀:1

我是否使用mapreduce或者我可以使用聚合函数来实现这一目标吗?谢谢。

0 个答案:

没有答案