go mongo 根据时间删除

 

 

 

//timeStr  是参数  yyyy-mm-dd hh:ff:mm

toDate, _ := time.Parse("2006-01-02 15:04:05", timeStr)

ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)

filter = bson.M{"ts": bson.M{"$lt": toDate}, "used": bson.M{"$ne": 1}}


deleteResult, _ := mongodb.Conn().Collection(tableName).DeleteMany(ctx, filter)


 

posted @ 2022-04-21 15:12  AngDH  阅读(373)  评论(0编辑  收藏  举报