Jamers Posted February 22, 2019 Report Share Posted February 22, 2019 $where 使用示例: db.test.find({ "detail.test": {$nin:[null],$exists: true}, $where: function() { var ret = false; for(var curr in this.detail.test) { //print(this.detail.test[curr].nums); if (this.detail.test[curr].nums >= 100) { ret = true; break; } } return ret; } }); 以上仅为演示使用$where的方式,上面的功能推荐用子元素匹配处理,上面的效率太低了 db.test.find({ 'detail.test': { '$elemMatch': {'nums': {'$gte': 100}} }, } 查看print输出日志需要到服务器上直接查看日志,不推荐打开日志 tail -f /var/db/mongodb/mongod.log Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now