這個東西用的好少,每次要用的時候都想不起來,記一下吧
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}}})
恩,就這樣