diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index 70748946..b6b3d8fc 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -1186,6 +1186,10 @@ func (m *Mongo) GetMomentListByMid(ctx *gin.Context, req *momentproto.OpListByMi list := make([]*dbstruct.Moment, 0) col := m.getColMoment() //ct_lower_bound < ct <= ct_upper_bound + query := qmgo.M{ + "mid": util.DerefInt64(req.Mid), + "del_flag": 0, + } ctClause := qmgo.M{} if req.CtLowerBound != nil { ctClause["$gt"] = util.DerefInt64(req.CtLowerBound) @@ -1193,10 +1197,8 @@ func (m *Mongo) GetMomentListByMid(ctx *gin.Context, req *momentproto.OpListByMi if req.CtUpperBound != nil { ctClause["$lte"] = util.DerefInt64(req.CtUpperBound) } - query := qmgo.M{ - "mid": util.DerefInt64(req.Mid), - "ct": ctClause, - "del_flag": 0, + if len(ctClause) != 0 { + query["ct"] = ctClause } err := col.Find(ctx, query).Sort("-ct").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list) if err == qmgo.ErrNoSuchDocuments { @@ -1210,6 +1212,12 @@ func (m *Mongo) GetMomentListByMids(ctx *gin.Context, req *momentproto.OpListByM list := make([]*dbstruct.Moment, 0) col := m.getColMoment() //ct_lower_bound < ct <= ct_upper_bound + query := qmgo.M{ + "mid": bson.M{ + "$in": req.Mids, + }, + "del_flag": 0, + } ctClause := qmgo.M{} if req.CtLowerBound != nil { ctClause["$gt"] = util.DerefInt64(req.CtLowerBound) @@ -1217,12 +1225,8 @@ func (m *Mongo) GetMomentListByMids(ctx *gin.Context, req *momentproto.OpListByM if req.CtUpperBound != nil { ctClause["$lte"] = util.DerefInt64(req.CtUpperBound) } - query := qmgo.M{ - "mid": bson.M{ - "$in": req.Mids, - }, - "ct": ctClause, - "del_flag": 0, + if len(ctClause) != 0 { + query["ct"] = ctClause } err := col.Find(ctx, query).Sort("-ct").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list) if err == qmgo.ErrNoSuchDocuments {