这个东西用的好少,每次要用的时候都想不起来,记一下吧

 

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}}})

 

 

  恩,就这样

相关文章:

  • 2021-12-23
  • 2021-11-30
  • 2022-01-25
  • 2021-12-29
  • 2022-01-14
  • 2021-05-27
  • 2022-02-19
猜你喜欢
  • 2022-12-23
  • 2021-05-17
  • 2021-12-06
  • 2022-01-17
  • 2022-02-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案