您的位置:首页 > 数据库 > Mongodb

MongoDB 查询非空数组

2016-10-10 15:57 253 查看
转载自:http://blog.csdn.net/caisong/article/details/49639973

mongdb非空数组查询

初始数据

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


查询非空

//方式一
db.test_tab.find({array:{$elemMatch:{$ne:null}}})
//方式二
db.test_tab.find({$where:"this.array.length>0"})


结果

{ "_id" : ObjectId(""), "array" : [ 1, 2, 3, 4, 5] }


错误查询

db.test_tab.find({array:{$ne:null}})
db.test_tab.find({"array.0":{$ne:null}})


查询空数组

db.test_tab.find({array:{$size:0}})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mongodb 数据