-3

Here is what I have done so far

filter := bson.M{
    "$or": bson.A{
        bson.M{"title": bson.M{"$regex": "input"}},
        bson.M{"author": bson.M{"$regex": "input"}},
        bson.M{"content": bson.M{"$regex": "input"}},
    },
}

p.postProposalCollection.Find(ctx, filter)

but it is case sensitive, is there anyway to lowercase the column title, author, content then try to search with regex.

Chau Loi
  • 1,106
  • 1
  • 14
  • 36

1 Answers1

1

To do the case-insensitive regex search, you can use the Regex primitive with "i" flag:

bson.M{"title": bson.M{"$regex": primitive.Regex{Pattern: "input", Options: "i"}}},

See here and here for details.

jabbson
  • 4,390
  • 1
  • 13
  • 23