MongoDB客户端:
1,NoSQL Manager for MongoDB
2,Robomongo(推荐,好多教程上的语句能够直接使用)
不一样的客户端执行语句有差别
参考:https://docs.mongodb.com/manual/reference/operator/aggregation/count/web
一,NoSQL Manager for MongoDB客户端语句mongodb
1,id查询使用ObjectIdcookie
2,时间查询使用ISODatedom
{ "_id" : ObjectId("5b498fb070bb993b335ab1c0"), "_class" : "com.onloon.custom.data.model.importdata.DetectiveTask", "keywords" : "pear", "status" : 0, "userId" : "645a828883714b679dc5d004e93dc192", "serverLevel" : "1", "createDate" : "20180714", "createTime" : ISODate("2018-07-14T05:52:48.584Z"), "updateTime" : ISODate("2018-07-14T05:52:48.584Z"), "countries" : "Russia&&United Kingdom" }
{"userId":"645a828883714b679dc5d004e93dc192", "_id" : ObjectId("5b498fb070bb993b335ab1c0"),"createTime" : {$gte : ISODate("2018-07-14T05:52:48.584Z")}}
二,Robomongo客户端url
1,SUMspa
按照productType统计pv的总和:3d
{
"_id" : ObjectId("598bb71370bb9933cf6fa196"),
"_class" : "com.onloon.website.analytics.core.entity.ProductTrafficBean",
"productId" : "83277ed6be2f4e46b6fbdc6866416e94",
"platform" : 0,
"shopId" : "151623511167744942",
"pv" : NumberLong(3),
"uv" : NumberLong(1),
"uvTime" : NumberLong(252186),
"msgProductCount" : 2,
"date" : "2017-08-10",
"productType" : "1",
"cookie" : ""
}code
db.getCollection('doc_product_traffic').aggregate([{$group : {_id : "$productType", num_tutorial : {$sum : "$pv"}}}])
按照pageType统计总数:orm
{
"_id" : ObjectId("5a7d975c01c56936f40d1f27"),
"_class" : "com.onloon.website.analytics.core.entity.PageDirectBean",
"pageId" : "aa123a",
"pageType" : 2,
"redirectUrl" : "www.baidu.com"
}server
db.getCollection('pageDirectBean').aggregate([{$group : {_id : "$pageType", num_tutorial : {$sum : 1}}}])
2,COUNT
{“_ id”:ObjectId(“54936 ... dd0c”),“last_name”:“smith”,“first_name”:“mike”} {“_ id”:ObjectId(“54936 ... dd0d”),“last_name”:“smith “,”first_name“:”william“} {”_ id“:ObjectId(”54936 ... dd0e“),”last_name“:”smith“,”first_name“:”william“} {”_ id“:ObjectId(”54936 ... dd0f“),”last_name“:”smith“,”first_name“:”mark“}
> db.collection.find({“last_name”:“smith”}).count();> db.collection.distinct(“first_name”,{“last_name”:“smith”}).length;
独立站点总IP数:
{ "_id" : ObjectId("595dada070bb99301b45695a"), "_class" : "com.onloon.website.analytics.core.entity.PageViewLogBean", "domain" : "baidu.com", "url" : "dsds", "pageTitle" : "商品详情", "pageId" : "3232", "cookie" : "aba7981f-332a-421a-8a56-82095ddad5dd", "viewDate" : NumberLong(1499311520843), "viewFrom" : "0", "shopId" : "3232", "ip" : "223.93.170.250", "platform" : 0, "date" : "2017-07-06" } db.getCollection('doc_page_view_log').aggregate([{$match:{viewDate:{$lt:1532016000000}}},{$group: {_id: '$ip'} },{$count:"ipcount"}])
侦探次数:
{ "_id" : ObjectId("5acf4e0170bb9918956ce28d"), "_class" : "com.onloon.custom.data.model.importdata.DetectiveTask", "keywords" : "phone", "status" : 0, "userId" : "83fcb7323c9a47de98403be7cedb9433", "serverLevel" : "1", "createDate" : "20180412", "createTime" : ISODate("2018-04-12T12:16:01.885Z"), "updateTime" : ISODate("2018-04-12T12:16:01.885Z") } db.getCollection('detectiveTask').count({"createTime" : {$lte : ISODate("2018-07-20T00:00:00.584Z")}})