【发布时间】:2018-05-22 15:01:21
【问题描述】:
在 MongoDB 数据库中,我想将数组“位置”的值转换为地理坐标(去掉双引号)。
现在我有:
{"location" : ["12.962828", "37.987717"]}
我需要:
{"location" : [12.962828, 37.987717]}
我该怎么办?
谢谢
【问题讨论】:
-
@Danielle:我需要稳定转换数组值。我用下面的代码尝试了 parseInt、parseFloat,但结果是:{location: NaN,NaN}:
db.strutture.find({Codice: "xx-yy-zzz-111"}).forEach( function (x) { var long = parseFloat("x.location.0"); var lat = parseFloat("x.location.1"); x.location = [long,lat]; db.strutture.save(x); });
标签: mongodb