From 27327019bef25bd673efb57657c5d8a06a5a40ae Mon Sep 17 00:00:00 2001 From: mr Date: Thu, 1 Aug 2024 10:02:40 +0200 Subject: [PATCH] logs --- dbs/mongo/mongo.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/dbs/mongo/mongo.go b/dbs/mongo/mongo.go index 98a8b5b..baa5ff9 100644 --- a/dbs/mongo/mongo.go +++ b/dbs/mongo/mongo.go @@ -267,25 +267,23 @@ func (m *MongoDB) Search(filters dbs.Filters, collection_name string) (*mongo.Cu opts := options.Find() opts.SetLimit(100) targetDBCollection := CollectionMap[collection_name] - andList := []bson.E{} - for k, filter := range filters.And { - andList = append(andList, bson.E{Key: k, Value: bson.M{ - dbs.StringToOperator(filter.Operator).ToMongoOperator(): dbs.ToValueOperator(dbs.StringToOperator(filter.Operator), filter.Value)}}) - } - orList := []bson.M{} + orList := bson.A{} for k, filter := range filters.Or { orList = append(orList, bson.M{ k: bson.M{dbs.StringToOperator(filter.Operator).ToMongoOperator(): dbs.ToValueOperator(dbs.StringToOperator(filter.Operator), filter.Value)}}) } + f := bson.D{ + {"$or", orList}, + } + for k, filter := range filters.And { + f = append(f, bson.E{ + k, bson.M{ + dbs.StringToOperator(filter.Operator).ToMongoOperator(): dbs.ToValueOperator(dbs.StringToOperator(filter.Operator), filter.Value), + }}) + } + MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - f := bson.D{} - if len(andList) > 0 { - f = append(f, andList...) - } - if len(orList) > 0 { - f = append(f, bson.E{Key: "$or", Value: orList}) - } fmt.Println("FILTER", f) if cursor, err := targetDBCollection.Find( MngoCtx,