機能をリクエストしバグを報告しますか?
考えられるバグ
現在の動作は何ですか?
地理空間に座標を保存できません
ここに来て申し訳ありませんが、解決策が見つかりません。
これは私のスキーマです:
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のバージョンを教えてください。
最新
新しい問題を作成する際に参照されている寄稿ガイドラインからの引用:
マングース(バグレポートではない)について質問がある場合は、 StackOverflowまたは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] };
@Inatenoありがとう...そうです!!
最も参考になるコメント
これが私がそれをする方法です、これが助けになることを願っています