首页 > 编程知识 正文

mongodb查询某个字段是否为空,判断字符串数组是否为空

时间:2023-05-03 12:06:53 阅读:231142 作者:2493

 方法一:{"field1.0":{$exists: true}} (推荐)

db.testcollection.find({"field1.0":{$exists: true}})

方法二:$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: []}})

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。