Ramesh Kunhiraman
Ramesh Kunhiraman

Reputation: 11

GO based Mongo Aggregate Query issue

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"}}}}

Upvotes: 0

Views: 279

Answers (1)

Zippo
Zippo

Reputation: 16440

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"}}}}}

Upvotes: 1

Related Questions