mongodb查詢非空數組


這個東西用的好少,每次要用的時候都想不起來,記一下吧

 

orderHistory是個數組:

  方法一:  db.photos.find({"orderHistory":{$elemMatch:{$ne:null}}},{orderHistory:1})

        重點: $elemMatch:{$ne:null}

  方法二:  db.photos.find({$where:"this.orderHistory.length>0"})

        重點:$where:"this.orderHistory.length>0"

  方法三:  db.photos.find({"orderHistory.0":{$exists: true}})

        重點:這個最簡單

  方法四:  db.photos.find({"orderHistory":{$gt: []}})

        重點:。。。。。。

  方法五:  db.photos.find({"orderHistory":{$not: {$size: 0}}})

 

 

  恩,就這樣


免責聲明!

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



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