mongoose 多条件 模糊查询
生活随笔
收集整理的這篇文章主要介紹了
mongoose 多条件 模糊查询
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
需要知道兩個標識符就可以搞定。
$or 用于多條件查詢 http://www.nodeclass.com/api/mongoose.html#query_Query-or
$regex 用于模糊查詢 http://www.nodeclass.com/api/mongoose.html#query_Query-regex
試例代碼:
//從URL中傳來的 keyword參數 const keyword = this.params.keyword //不區分大小寫 const reg = new RegExp(keyword, 'i') const result = await User.find({$or : [ //多條件,數組{nick : {$regex : reg}},{email : {$regex : reg}}]},{password : 0 // 返回結果不包含密碼字段},{sort : { _id : -1 },// 按照 _id倒序排列limit : 100 // 查詢100條} )總結
以上是生活随笔為你收集整理的mongoose 多条件 模糊查询的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Modbus通讯模拟环境的搭建(一) —
- 下一篇: 杂七杂八的小技巧