V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
Achilless
V2EX  ›  Go 编程语言

go 操作 mongodb 执行聚合查询,并根据时间过滤

  •  
  •   Achilless · 2020-06-03 10:46:08 +08:00 · 1925 次点击
    这是一个创建于 1423 天前的主题,其中的信息可能已经有所发展或是发生改变。

    现在我写的 pipe 是这样:

    pipe := []bson.M{ {"$match": bson.M{ "updateTime":bson.M{"$gt":"2020-06-03T09:21:22.878+08:00"}}}, {"$group": bson.M{ "_id": "$sn", "count": bson.M{"$sum": 1}, }}, }

    但是返回是空,时间没有问题,mongo 里这个字段的格式是:ISODate("2020-06-03T09:21:22.878+08:00") 如果去掉 match,只留 group,返回正常,说明程序是没问题,纠结于这里 match 如何写

    joesonw
        1
    joesonw  
       2020-06-03 13:13:29 +08:00
    primitive.NewDateTimeFromTime?
    Achilless
        2
    Achilless  
    OP
       2020-06-03 16:26:57 +08:00
    搞定了,直接传 time.Now()不需要格式化
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   904 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 21:13 · PVG 05:13 · LAX 14:13 · JFK 17:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.