$ 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