#日PV
mongo localhost:30000 <<eof
use weblogs
#条件查询
db.n_uu_access_log.find({'time':{\$gte: new Date($d1),\$lt: new Date($d2)}}).count()
eof
#独立IP
mongo localhost:30000 <<eof
use weblogs
#嵌套查询
db.n_uu_access_log.distinct('host',{'time':{\$gte: new Date($d1),\$lt: new Date($d2)}})
db.n_uu_access_log.distinct('host',{'time':{\$gte: new Date($d1),\$lt: new Date($d2)}}).length
eof
#状态
mongo localhost:30000 <<eof
use weblogs
#分组查询
db.n_uu_access_log.group({key:{'code':true},cond:{'time':{\$gte: new Date($d1),\$lt: new Date($d2)}},reduce:function(obj,prev){prev.count+=1},initial:{count:0}})
eof

分组统计
key:要分组的列。本例中为code
cond:分组条件,可以理解为where条件内容本例为time
reduce:分组的计算方法。本例中为count+=1
initial:分组计算的初始值。本例中count 是从0 算起的