mongo-查询(4)——正则表达式


mongo的find中,还可以使用正则表达式。

> db.tianyc02.find({name:/xTtt/i})
{ "_id" : ObjectId("50ea6eba12729d90ce6e3423"), "name" : "xttt", "age" : 111 }
{ "_id" : ObjectId("50ea6eba12729d90ce6e3424"), "name" : "xttt", "age" : 222 }

> db.tianyc02.find({name:/xTt$/i})
{ "_id" : ObjectId("50ea6b6f12729d90ce6e341b"), "name" : "xtt", "age" : 11, "sex" : null }
{ "_id" : ObjectId("50ea6b7312729d90ce6e341c"), "name" : "xtt", "age" : 22, "sex" : "m" }
>

mongo使用perl兼容的正则表达式库来匹配正则表达式。建议在使用正则作为mongo的查询条件前,先在js shell中检查一下语法。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM