$ in中的正則表達式查詢不起作用。它在mongo shell中工作正常。基於GO的Mongo Aggregate查詢問題
不起作用:
OpMatch := bson.M{"$match": bson.M{"wordname": bson.M{"$in": [...]string{"/^how$/"}}}}
作品:
OpMatch := bson.M{"$match": bson.M{"wordname": bson.M{"$in": [...]string{"how"}}}}
$ in中的正則表達式查詢不起作用。它在mongo shell中工作正常。基於GO的Mongo Aggregate查詢問題
不起作用:
OpMatch := bson.M{"$match": bson.M{"wordname": bson.M{"$in": [...]string{"/^how$/"}}}}
作品:
OpMatch := bson.M{"$match": bson.M{"wordname": bson.M{"$in": [...]string{"how"}}}}
那不是你該怎樣與MgO的正則表達式。您必須使用bson.RegEx
。試試這個:
bson.M{"$match": bson.M{"wordname": bson.M{"$in": []bson.RegEx{{"^how$", "i"}}}}}
感謝@Moshe Revah了很不錯的反響。我如何添加多個模式?例如'{$ match:{「wordname」:{$ in:[/^how $ /,/^to $ /,/^stop $ /,/^neck $ /,/^pain $ /]}}} ,' –
嘿摩西。我解決了處理多種模式的問題。再次感謝。 'bson.M {「$ match」:bson.M {「wordname」:bson.M {「$ in」:[] bson.RegEx {bson.RegEx {「^ how $」,「i」}},bson .RegEx {「^ to $」,「i」}}}}}' –
因此,使用什麼工作 – Sridhar