The Go Programming Language
› http://golang.org/
› Go Playground
Go Projects
› Revel Web Framework
Achilless

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

  •  
  •   Achilless · Jun 3, 2020 · 2744 views
    This topic created in 2345 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
    joesonw
    Jun 3, 2020
    1
    primitive.NewDateTimeFromTime?
    Achilless
    Achilless
    OP
    Jun 3, 2020
    2
    搞定了,直接传 time.Now()不需要格式化
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1712 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 23:41 · PVG 07:41 · LAX 15:41 · JFK 18:41
    ♥ Do have faith in what you're doing.