0

I tried to query:

bson.M{"name": bson.M{"$regex": bson.RegEx{Pattern: "sophia", Options: "i"}} 

but, it also query out which part matched with "sophia".

I only want to query out the items which case insensitive.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
sophiageng
  • 49
  • 1
  • 6
  • e.g the items with name "so" also be queried from above code – sophiageng May 18 '18 at 09:21
  • I don't understand your question. You seem to be saying that the query does what you want... ? – Jonathan Hall May 18 '18 at 09:22
  • In addition to using a correct regular expression to match your "word only", if you go way down the list of answers on the MongoDB specific question you will [see one that covers case insensitive collation](https://stackoverflow.com/a/40914924/2313887) as is now supported in modern releases of MongoDB. This would generally be preferable for an "exact match" than using a regex. – Neil Lunn May 18 '18 at 09:36

0 Answers0