How to make “LIKE” query work in MongoDB?

后端 未结 7 1695
梦谈多话
梦谈多话 2021-01-03 00:07

I have a list of street names and I want to select all that start with \"Al\". In my MySQL I would do something like

SELECT * FROM streets WHERE \"street_nam         


        
7条回答
  •  离开以前
    2021-01-03 00:47

    $collection.find({"name": /.*Al.*/})

    or, similar,

    $collection.find({"name": /Al/})

    You're looking for something that contains "Al" somewhere (SQL's '%' operator is equivalent to regexps' '.*'), not something that has "Al" anchored to the beginning of the string.

提交回复
热议问题