【发布时间】:2013-06-11 08:52:29
【问题描述】:
我一直在尝试使用 node/express/backbone/mongoose 从表单中保存坐标 - 这可能与 MongoDB 本身有关
这是我的架构:
var MySchema = new mongoose.Schema({
loc: {type:{type: String}, coordinates:[]}
});
然后
var My = mongoose.model('My', MySchema);
var registerMy = function(loctype, longi, lati) {
var MyMy = new My({
loc: {
type:loctype,
coordinates:[longi,lati]
}
});
}
来自 HTML 表单
<form>
<fieldset>
<label>
Loctype:
<input type="text" name="loctype" />
</label>
<label>
Longitude:
<input type="number" name="longi" />
</label>
<label>
Latitude:
<input type="number" name="lati" />
</label>
</fieldset>
<p>
<input type="submit" value="Register Now"/>
</p>
</form>
然后我得到这个错误:
{ [MongoError: 无法从对象中提取地理键,格式错误 几何?:{类型:“点”,坐标:[“37.677163”,“-1.696215”] }] name: 'MongoError', err: 'Can\'t extract geo keys from object, 畸形几何?:{类型:“点”,坐标:[“37.677163”, "-1.696215" ] }', 代码: 16572, n: 0, connectionId: 200, ok: 1 }
【问题讨论】:
-
好的,刚刚解决(我真的花了一天多才发到这里,但后来它亮了)所以答案只是在坐标内添加数字(坐标:[数字]}并且效果很好