title: How to write mongodb query for regex in GoLang using bson?
body: <p>I want to do wildcard search in records with firstname in mongodb using go mongodb driver.</p>
  
  <p>I'm using below query to achieve it.</p>
  
  <pre><code>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"}}})
  }
  </code></pre>
  
  <p>This is not working for me. Could you please correct me if I'm doing anything wrong.</p>
  
  <p>Even in and not in are also not working.</p>
  
  <pre><code>if len(cmd.StatusIn) &gt; 0 {
      filter = append(filter, bson.E{Key: "status", Value: bson.E{Key: "$in", Value: cmd.StatusIn}})
  }
  if len(cmd.StatusNotIn) &gt; 0 {
      filter = append(filter, bson.E{Key: "status", Value: bson.E{Key: "$nin", Value: cmd.StatusNotIn}})
  }
  </code></pre>
  
  <p>cmd.StatusIn is slice of string ([]string)</p>