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