【问题标题】:MongoDB nearSphere only returns 100 results?MongoDB nearSphere 只返回 100 个结果?
【发布时间】:2012-10-10 10:15:43
【问题描述】:

为什么 $nearsphere 查询总是返回 100 个结果?

 db.mytable.find({"geo":{"$nearSphere":[41.393552,2.171344999999974],"$maxDistance":0.007}}).limit(500).count() -->>> 100 results

无论 $maxdistance 的值如何,我的表都有超过 30.000 条记录。

【问题讨论】:

    标签: node.js mongodb


    【解决方案1】:

    【讨论】:

    【解决方案2】:

    我认为异步代码正在命中 db.close();在 .each 循环完成之前,由于某种原因,每个人都只能得到 100 个结果,所以这里有一个解决方法。

    var url = 'mongodb://localhost:27017/mydb';
    
    
      MongoClient.connect(url, function(err, db) {
    
           var i=0;
    
           var collection = db.collection('documents');
    
           collection.find().each(function(err, docs) {
    
             if (docs != null){
    
                console.log(docs);
                console.log(i);
    
                i++;
    
                if( i >= docs.length ){
                  db.close();
                }
    
              }
    
    
      });
    
    
    });
    

    【讨论】:

      猜你喜欢
      • 2017-09-15
      • 1970-01-01
      • 2021-03-27
      • 1970-01-01
      • 2016-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多