mongodb查询非空数组的几种方法

一、elemMatch和ne

db.Collection.find({array:{KaTeX parse error: Expected '}', got 'EOF' at end of input: elemMatch:{ne:null}}})

二、$where

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

三、not和size

db.Collection.find({array: {KaTeX parse error: Expected '}', got 'EOF' at end of input: 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: [] } })

详情

你可能感兴趣的:(MongoDB)