新手问题 MongoDB 下如何模糊查询字段以 XXX 开头的数据?

lehug · March 24, 2016 · Last by karloku replied at March 24, 2016 · 9518 hits

mongodb 下如何模糊查询字段以 XXX 开头的数据?我知道 Table.where(:tag=>/#{tag}/) 这个可以,但是有没有更精确的按照开头匹配的语句写法?

这是个正则问题 /^xxx/ 或者 /\Axxx/ ^是行首,\A是字符串头,根据情况选择 尽量避免用以上两种之外的正则查询,性能堪忧...

lehug closed this topic. 30 Oct 08:28
You need to Sign in before reply, if you don't have an account, please Sign up first.