I'm trying to save coordinates in my 2dsphere
model.
This is my model:
var userSchema = new Schema({
email: {
type: String,
required: true,
unique: true
},
...
loc: {
type: {
type: "String",
required: true,
enum: ['Point', 'LineString', 'Polygon'],
default: 'Point'
},
coordinates: [Number]
}
});
userSchema.index({'loc': '2dsphere'});
const User = mongoose.model('User', userSchema);
module.exports = User
My query to save new data is formated as follow:
email:eu@vc.com
password:t12345
name:Igor
type:true
loc:{
coordinates: [-43.306174, -22.844279]
}
And this is the error that I recieve:
{
"code": 16804,
"index": 0,
"errmsg": "location object expected, location array not in correct format",
"op": {
"email": "eu@vc.com",
"password": "t12345",
"name": "Igor",
"_id": "5a311c016d15fc235895bef3",
"created_at": "2017-12-13T12:24:33.493Z",
"loc": {
"coordinates": [],
"type": "Point"
},
"type": true,
"__v": 0
}
}