1

i am working on a nodeJS application with mongoDB and i am trying to get all users next to the current user...

my real problem is that my application works quiet well when my query is based on a "2d" index ( i got about 25000 responses in 1 min ) but when i am trying the same with a "2dsphere" index i have high latency time (1 request take more than 2 seconds of execution)...

Here is my request :

app.get('/findInsertLocGeoNear100true', function(req, res) {
    var obj = getRandomCoordonnee();//"obj" = random longitude and latitude.
      userModel.geoNear({
       type: "Point" ,
       coordinates: [ obj.lat,obj.lng ]
    },
    { maxDistance : 5,
      spherical : true,
      num : 100   
    },
    function(err, results, stats) {
        res.json(200, results);
       console.log(err);
    });
});

And here is my schema mongoose :

var userSchema = new mongoose.Schema({
  loc: {type: [Number]},
  name : { type : String, match: /^[a-zA-Z0-9-_]+$/ },
  dateLastActivity : { type : Date, default : Date.now },
  type: Number
});

NB: MongoDB runs on an ubuntu server and my index is created with "db.users.ensureIndex({"loc":"2dsphere"})"

If you have any advices, best practices or suggestions to improve my performances, i would be glad to heard them. Thanks ! Best regards.

Antonin
  • 11
  • 2
  • Can you include an explain for the slow 2dsphere query? Why aren't you using GeoJson points for your `loc` field in the documents? – wdberkeley Jan 14 '15 at 21:04

0 Answers0