Mongoose: إدراج الاستعلام الجغرافي المكاني

تم إنشاؤها على ١٤ ديسمبر ٢٠١٧  ·  3تعليقات  ·  مصدر: Automattic/mongoose

هل تريد طلب ميزة أو الإبلاغ عن خطأ ؟

علة محتملة

ما هو السلوك الحالي؟

لا يمكن حفظ الإحداثيات في الجغرافيا المكانية

آسف للمجيء إلى هنا ، لكن لا يمكنني العثور على حل.

هذا هو مخطط بياني:

var mongoose     = require('mongoose');
var Schema       = mongoose.Schema;

var userSchema   = new Schema({
  email: {
      type: String,
      required: true,
      unique: true
    },
    password: {type: String, required: true},
    name: {type: String, required: true},
    type: {type: Boolean, default: false, required: true},
    geo: {
      type: { type: String, enum: "Point", default: "Point" },
      coordinates: { type: [ Number ],   default: [ 0,0 ] }
    }
});

userSchema.index({geo: '2dsphere'})
const User = mongoose.model('User', userSchema);
module.exports = User

أحاول إدخال رقم قياسي جديد:

db.users.insert({email: '[email protected]', password: 'tebrwrw', name: 'teste', type: true, geo: { coordinates: [ 40, 5 ]} })

وأنا أتلقى هذا الخطأ:

WriteResult({
        "nInserted" : 0,
        "writeError" : {
                "code" : 16755,
                "errmsg" : "Can't extract geo keys: { _id: ObjectId('5a31d79f369885e770a989b7'), email: \"[email protected]\", password: \"tebrwrw\", name: \"teste\", type: true, geo: { coordinates: [ 40.0, 5.0 ] } }  unknown GeoJSON type: { coordinates: [ 40.0, 5.0 ] }"
        }
})

يرجى ذكر إصدار node.js و mongoose و MongoDB.
آخر

التعليق الأكثر فائدة

إليكم كيف أفعل ذلك ، آمل أن يساعد هذا

    // in the schma declaration
    'loc': { type: { type: String, enum: "Point", default: "Point" }, coordinates: { type: [Number], default: [0,0] } }

    // after schema declaration*
    schema.index( { loc: "2dsphere" } );

    // and then, how I create it
    model.loc = { type: "Point", coordinates: [newarena.lng, newarena.lat] };

ال 3 كومينتر

الاقتباس من إرشادات المساهمة المشار إليها عند إنشاء عدد جديد:

إذا كان لديك سؤال حول النمس (ليس تقرير خطأ) ، فيرجى إرساله إما إلى Gitter

من المرجح أن تحصل على استجابة في وقت أقرب بكثير على أيٍّ من هؤلاء بينما لا تضيف إلى تراكم الأخطاء / الميزات التي يحتاج القائمون على الصيانة إلى التدقيق فيها هنا.

إليكم كيف أفعل ذلك ، آمل أن يساعد هذا

    // in the schma declaration
    'loc': { type: { type: String, enum: "Point", default: "Point" }, coordinates: { type: [Number], default: [0,0] } }

    // after schema declaration*
    schema.index( { loc: "2dsphere" } );

    // and then, how I create it
    model.loc = { type: "Point", coordinates: [newarena.lng, newarena.lat] };

MustafaHosny اللهم امين ...

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات