This commit is contained in:
mr 2024-08-01 10:02:40 +02:00
parent 1f8aefb7d8
commit 27327019be

View File

@ -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,