私はmongoDBを使用してnodeJSアプリケーションに取り組んでおり、現在のユーザーの隣にすべてのユーザーを取得しようとしています...
私の本当の問題は、クエリが「2d」インデックスに基づいている場合(1分で約25000の応答が得られた場合)、アプリケーションが静かに動作することですが、「2dsphere」インデックスで同じことをしようとすると、待ち時間が長くなります( 1 つのリクエストの実行に 2 秒以上かかります)...
ここに私の要求があります:
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);
});
});
そして、ここに私のスキーママングースがあります:
var userSchema = new mongoose.Schema({
loc: {type: [Number]},
name : { type : String, match: /^[a-zA-Z0-9-_]+$/ },
dateLastActivity : { type : Date, default : Date.now },
type: Number
});
注意: MongoDB は ubuntu サーバーで実行され、私のインデックスは "db.users.ensureIndex({"loc":"2dsphere"})" で作成されます
パフォーマンスを向上させるためのアドバイス、ベスト プラクティス、または提案があれば、喜んでお聞きします。ありがとう !よろしくお願いします。