【发布时间】:2016-03-15 19:14:50
【问题描述】:
以下是我的位置集合架构:
var LocationSchema = new Schema({
street : {type: String, required: true},
area : {type: String, required: true},
city : {type: String, required: true},
state : {type: String, required: true},
zip : {type: String, required: true},
country : {type: String, default: 'IN'},
pointers:{type: [], index: '2dsphere'}
});
使用 mongoose 指针在 mongo 中保存数据时,存储为字符串而不是数字。得到以下回复:
"street": "rani sati marg",
"area": "malad east",
"city": "mumbai",
"state": "maharashtra",
"zip": "400097",
"pointers": [
"72.857452,19.857452"
],
"country": "IN"
我想要数字中的指针值,例如:[72.857452,19.857452]
【问题讨论】:
-
您实际上并没有要求它。
"pointers": { "type": [Number], "index": "2dphere" }实际上声明数组中的内容 必须 是数字,并且在像您所做的那样发送“字符串”数组时将“自动转换”。 -
然后在验证时将 Cast to Array 转换为值错误。