Apakah Anda ingin meminta fitur atau melaporkan bug ?
kemungkinan bug
Apa perilaku saat ini?
tidak dapat menyimpan koordinat di geospasial
Maaf datang ke sini, tetapi saya tidak dapat menemukan solusi.
Ini skema saya:
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
Saya mencoba memasukkan catatan baru:
db.users.insert({email: '[email protected]', password: 'tebrwrw', name: 'teste', type: true, geo: { coordinates: [ 40, 5 ]} })
dan saya mendapatkan kesalahan ini:
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 ] }"
}
})
Sebutkan versi node.js, luwak, dan MongoDB Anda.
terbaru
Mengutip dari pedoman kontribusi yang direferensikan saat membuat masalah baru:
Jika Anda memiliki pertanyaan tentang Mongoose (bukan laporan bug) silakan kirim ke StackOverflow , atau di Gitter
Anda lebih mungkin mendapatkan respons lebih cepat pada salah satu dari mereka sementara tidak menambah tumpukan bug/fitur yang perlu disaring oleh pengelola di sini.
Inilah cara saya melakukannya, semoga membantu
// 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] };
@Inateno terima kasih... kan!!
Komentar yang paling membantu
Inilah cara saya melakukannya, semoga membantu