From 487ce31c4cd5b2d7dd530a48fbccbfc32cef5788 Mon Sep 17 00:00:00 2001 From: eson Date: Wed, 9 Dec 2020 18:18:09 +0800 Subject: [PATCH] fix(time): mongo query error --- collect.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/collect.go b/collect.go index f4f13e5..01272d4 100644 --- a/collect.go +++ b/collect.go @@ -16,20 +16,28 @@ import ( func collectCopyCountLiveAnchors(cxt *WorkerContext) { defer cxt.Done() + var err error + var ok bool for !ps.IsClose() { liveanchor := &CountLiveAnchors{} - ok, err := db.T.CountLiveAnchors.OrderBy("create_at desc").Limit(1).Get(liveanchor) + ok, err = db.T.CountLiveAnchors.OrderBy("create_at desc").Limit(1).Get(liveanchor) if ok || (ok == false && err == nil) { var cur *mongo.Cursor + var last time.Time if ok == false { - cur, err = mdb.C.CountLiveAnchors.Find(context.TODO(), bson.M{"create_at": bson.M{"$gt": "2020-05-30"}}) + last, err = time.ParseInLocation("2006-01-02", "2020-05-30", time.Local) + if err != nil { + panic(err) + } + cur, err = mdb.C.CountLiveAnchors.Find(context.TODO(), bson.M{"create_at": bson.M{"$gt": last}}) } else { - last := liveanchor.CreateAt + last = liveanchor.CreateAt log.Println("last: ", last) cur, err = mdb.C.CountLiveAnchors.Find(context.TODO(), bson.M{"create_at": bson.M{"$gt": last}}) } + if err != nil { log.Println(err) ps.Wait(time.Second * 5)