记录下MongoDB用于判断数组是否为空的语句。
- 方法一:{“field1.0”:{$exists: true}} (推荐)
db.testcollection.find({"field1.0":{$exists: true}})
- 方法二:KaTeX parse error: Expected '}', got 'EOF' at end of input: elemMatch:{ne:null}
db.testcollection.find({"field1":{$elemMatch:{$ne:null}}})
- 方法三:$where:“this.field1.length>0”
db.testcollection.find({$where:"this.field1.length>0"})
- 方法四:{“field1”:{$gt: []}}
db.testcollection.find({"field1":{$gt: []}})