基于GO的Mongo聚合查询问题

The regular expression query in $in is not working. It works fine in the mongo shell.

Does not work:

OpMatch := bson.M{"$match": bson.M{"wordname": bson.M{"$in": [...]string{"/^how$/"}}}}

Works:

OpMatch := bson.M{"$match": bson.M{"wordname": bson.M{"$in": [...]string{"how"}}}}

That's not how you do regex with mgo. You must use bson.RegEx. Try this:

bson.M{"$match": bson.M{"wordname": bson.M{"$in": []bson.RegEx{{"^how$", "i"}}}}}