V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
Achilless

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

  •  
  •   Achilless · Jun 3, 2020 · 2338 views
    This topic created in 2166 days ago, the information mentioned may be changed or developed.

    现在我写的 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  
       Jun 3, 2020
    primitive.NewDateTimeFromTime?
    Achilless
        2
    Achilless  
    OP
       Jun 3, 2020
    搞定了,直接传 time.Now()不需要格式化
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2957 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 12:48 · PVG 20:48 · LAX 05:48 · JFK 08:48
    ♥ Do have faith in what you're doing.