MongoDB使用sum和minimum treshhold进行聚合

时间:2017-04-25 11:54:23

标签: mongodb aggregation-framework

如何仅显示带有计数的结果> 10?

#!/bin/bash

curl_opts=()
read -r -e -p "What format do you want to use? json/xml?: " format

shopt -s nocasematch
case $format in
  json) curl_opts+=(-H "Content-Type: application/json") ;;
  xml)  curl_opts+=(-H "Content-Type: application/xml") ;;
  no)  printf 'Goodbye, you must specify a format to use Rest\n' >&2
       exit 1
       ;;
   *) printf 'Unknown format %s, exiting\n' "$format" >&2
      exit 1
      ;;
esac

curl "${curl_opts[@]}" ...

谢谢!

2 个答案:

答案 0 :(得分:0)

您可以在群组

后使用$ match进行过滤
 db.mydate.aggregate(
   [
      {
        $group : {
           _id : "Ident.url",
           count: { $sum: 1 }
        }
      },
      {$match: {count: {$gt:10}}}
   ]
)

答案 1 :(得分:0)

尝试使用match来过滤计数:

db.mydate.aggregate(
   [
      {
        $group : {
           _id : "Ident.url",
           count: { $sum: 1 }
        }
      },
      {
        $match : {
          count: {
            $gt: 10
          }
        }
      }
   ]
)