group by hour in mongodb按小时聚集

Reading time ~1 minute

mongodb使用起来着实灰常蛋疼, 难怪都喜欢使用Hive、Shark。而且语法也各种怪异。

如下实现在st表中将基于timestamp(存的是s而不是ms)的列按小时聚集count:

db.st.aggregate(
   [{'$match':{'type': "weibo"}},
    {'$group': {
        '_id': {'$subtract': ['$timestamp', {'$mod':'$timestamp', 3600]}]},
        'y': {'$sum': 1}}},
    {'$project': {'x': '$_id', 'y': '$y', '_id': 0}},
    {'$sort': {'x': 1}}])

等价于如下sql 伪代码

select (timestamp-timestamp%3600) as x,count(*) as y from st
where type='weibo'
group by x 
order by x asc

作作Technical笔记,以备后用。发现自己作的Technical笔记太少,倒了不少车轮子! 做笔记一则加深自己理解,一则前车以鉴来者。

Original post: http://blog.josephjctang.com/2013-11/mongodb-notes/

显示所有的生僻汉字

中日韩越包含很多生僻汉字,一般系统显示的都是常规汉字,网页显示不全,需要引入字体。而当前相对较全的字体有:- [遍黑体](https://github.com/Fitzgerald-Porthmouth-Koenigsegg/Plangothic_Project) 开源且更新较为及时。- [天...… Continue reading

个人近期时间日志分析

Published on February 23, 2019