missing context on search

This commit is contained in:
mr 2024-07-29 15:53:15 +02:00
parent d77a403150
commit 2f6fab2f7b

View File

@ -242,7 +242,7 @@ func (m *MongoDB) Search(search string, filter []string, collection_name string)
if strings.TrimSpace(search) == "*" {
search = ""
} else {
search = `(?i).*` + search + `.*`
search = `(?i).*` + strings.TrimSpace(search) + `.*`
}
targetDBCollection := CollectionMap[collection_name]
list := []bson.M{}
@ -253,7 +253,11 @@ func (m *MongoDB) Search(search string, filter []string, collection_name string)
defer cancel()
if cursor, err := targetDBCollection.Find(
MngoCtx, bson.M{"$or": list},
MngoCtx,
bson.M{"$or": []bson.M{
{"name": bson.M{"$regex": search}},
{"description": bson.M{"$regex": search}},
}},
opts,
); err != nil {
fmt.Println(0, bson.M{"$or": list})