Hi,
I am trying to find collection using "or" clause with multiple filter options inside bson.M{}.
I would like to get collection of customers start with either first name or last name.
But following code returning results after applying and clause. Can you please help with this code?
Thanks
filter := bson.M{}
if len(customerSearchRequest.FirstName) > 0 {
filter["customerprofile.firstname"] = primitive.Regex{Pattern: "^" + customerSearchRequest.FirstName, Options: "i"}
}
if len(customerSearchRequest.LastName) > 0 {
filter["customerprofile.lastname"] = primitive.Regex{Pattern: "^" + customerSearchRequest.LastName, Options: "i"}
}
cur, err := collection.Find(context.TODO(), filter, findOptions)