How to query MongoDB with “like”?

后端 未结 30 2073
予麋鹿
予麋鹿 2020-11-21 05:51

I want to query something with SQL\'s like query:

SELECT * FROM users  WHERE name LIKE \'%m%\'

How to do I achieve the same in

30条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-21 06:31

    In Go and the mgo driver:

    Collection.Find(bson.M{"name": bson.RegEx{"m", ""}}).All(&result)
    

    where result is the struct instance of the sought after type

提交回复
热议问题