mongdb非空数组查询

db.idap_zl.insert({array:[]})

db.idap_zl.insert({array:[1,2,3,4,5]})

db.idap_zl.find({array:{$elemMatch:{$ne:null}}})

 

一、elemMatchelemMatch和ne

db.Collection.find({array:{$elemMatch:{$ne:null}}})

二、$where

db.Collection.find({$where:"this.array.length>0"})

三、notnot和size

db.Collection.find({array: {$not: {$size: 0}}})

四、'.'路径和$exists

db.Collection.find({{'array.0': {$exists: 1}}})

五、existsexists和ne

db.Collection.find({ array: { $exists: true, $ne: [] } })

六、$gt

db.Collection.find({ array: { $gt: [] } })
 posted on 2020-03-11 17:17  xibuhaohao  阅读(2521)  评论(0编辑  收藏  举报