mongodb查詢非空數組的幾種方法


一、$elemMatch和$ne

db.Collection.find({array:{$elemMatch:{$ne:null}}})

二、$where

db.Collection.find({$where:"this.array.length>0"})

三、$not和$size

db.Collection.find({array: {$not: {$size: 0}}})

四、'.'路徑和$exists

db.Collection.find({{'array.0': {$exists: 1}}})

五、$exists和$ne

db.Collection.find({ array: { $exists: true, $ne: [] } })

六、$gt

db.Collection.find({ array: { $gt: [] } })

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM