I want to do wildcard search in records with firstname in mongodb using go mongodb driver.
I'm using below query to achieve it.
filter := bson.D{{Key: "tenantId", Value: cmd.TenantID}}
if cmd.FirstNameSearch != "" {
filter = append(filter, bson.E{Key: "firstName",
Value: bson.M{"$regex": primitive.Regex{Pattern: "^" + cmd.FirstNameSearch + "$", Options: "i"}}})
}
This is not working for me. Could you please correct me if I'm doing anything wrong.
Even in and not in are also not working.
if len(cmd.StatusIn) > 0 {
filter = append(filter, bson.E{Key: "status", Value: bson.E{Key: "$in", Value: cmd.StatusIn}})
}
if len(cmd.StatusNotIn) > 0 {
filter = append(filter, bson.E{Key: "status", Value: bson.E{Key: "$nin", Value: cmd.StatusNotIn}})
}
cmd.StatusIn is slice of string ([]string)