내가이 오류를 얻을쿼리 2dsphere 인덱스 누락에 대해 불평하지만, 나는 다음과 같은 코드를 실행하면
var mongoose = require("mongoose");
var LocationSchema = new mongoose.Schema({
userName: String,
loc: {
'type': { type: String, enum: "Point", default: "Point" },
coordinates: { type: [Number] }
}
})
LocationSchema.index({ category: 1, loc: "2dsphere" });
var Location = mongoose.model("location", LocationSchema);
var mongoDB = 'mongodb://user1:[email protected]:42417/locationdemo';
mongoose.Promise = global.Promise;
mongoose.connect(mongoDB, { useMongoClient: true });
var testUser = Location({
userName: "Tester",
loc: { coordinates: [12.44, 55.69] }
});
testUser.save(function (err) {
if (err) {
return console.log("UPPPPs: " + err);
}
console.log("User Saved, Try to find him:");
let query = Location.find({
loc:
{
$near:
{
$geometry:
{
type: "Point",
coordinates: [12.50, 55.71]
},
$maxDistance: 600000
}
}
})
query.exec(function (err, docs) {
if (err) {
return console.log("Err: " + err);
}
console.log("Found: " + JSON.stringify(docs))
})
});
이 (더 크게 예를 들어, 필수로 내려 삶은)입니다 :
Err: MongoError: error processing query: ns=locationdemo.locationsTree: GEONEAR field=loc maxdist=600000 isNearSphere=0 Sort: {} Proj: {} planner returned error: unable to find index for $geoNear query
을 그러나 인덱스는 아래에 있습니다 (10 줄 참조). 아래 mlab의 스크린 샷. 무엇이 잘못 되었습니까? :
:-) 인덱스 (배경)을 사용하는 올바른 방법에 대한 중요한 정보에 대한 닐 덕분에 당신이 당신의 문제를 해결하지 않는 생각 제공된 대답 뭔가가 있나요? 그렇다면 정확한 답변이 필요한 사항을 명확히하기 위해 답변에 의견을 말하십시오. 실제로 질문에 답하는 경우 질문에 [답변 수락] (https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)을 적어주십시오. ask –