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