2017-04-20 12 views
0

geoNearマングースとクエリエグゼキュータを取得することはできません。MongoError:私はMoongoseでgeoNearを使用してDBから結果を取得しようとしていますが、それは「クエリエグゼキュータを取得することはできません」というエラーを与えている


 
// Schema 
 
let dealSchema = new Schema({ 
 
userId: {type: String, required: true}, 
 
images: {type: [String], required: true}, 
 
location: { 
 
    lng: {type: Number}, 
 
    lat: {type: Number}, 
 
    name: {type: String, required: true} 
 
}, 
 
description: {type: String, required: false, default: ""}, 
 
expiredReports: {type: [String], required: false}, 
 
inappropriateReports: {type: [String], required: false}, 
 
likes: {type: [String], required: false}, 
 
dislikes: {type: [String], required: false}, 
 
comments: {type: [commentSchema], required: false}, 
 
creationDate: {type: Date, default: new Date()}, 
 
updationDate: {type: Date, default: new Date()} 
 
}, {collection: TableName.DEAL}); 
 

 

 
function getAll(radius) { 
 
var point = {type: "Point", coordinates: [9, 9]}; 
 

 
     let distance = parseInt(radius); 
 
     if (isNaN(distance)) { 
 
      return callback(new Error("Invalid Radius"), null) 
 
     } 
 

 
     var geoOptions = { 
 
      spherical: true, 
 
      maxDistance: distance, 
 
      num: 10 
 
     }; 
 

 
     DealData.geoNear(point, geoOptions, function (err, docs, stats) { 
 
       console.log(docs); 
 
      } 
 
     ); 
 
    
 
}

これはマングースの私のモデルとデータベースからデータを取得するための私のコードです。

答えて

0

geoNear方法は、そのインデックスを作成した後、あなたがCOORDSでデータを照会することができます、2dsphereインデックスが必要です。

例:

var mySchema = new mongoose.Schema({ 
    name: {type: String, required: true}, 
    location: {type: [Number], index: '2dsphere'} 
    }); 

場所フィールドの最初の項目は経度であり、第二つ@Artemたくさん

+0

おかげ緯度であります – user3768061

関連する問題