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: [] } })

 

posted @ 2018-10-17 11:00  yudis  阅读(6379)  评论(0编辑  收藏  举报