我正在将文件中的数据导入Rethinkdb。
数据看起来像这样(这是假数据)
[
{
"firstName": "Keeley",
"lastName": "Leannon",
"createdAt": "2016-05-10T19:55:38.823Z",
"location": {
"lat": 52,
"lng": 0.07687,
"lastUpdated": "2016-05-16T03:21:25.082Z"
},
"company": "Breitenberg and Sons",
"jobTitle": "Dynamic Group Facilitator",
"email": "Keeley.Leannon@derrick.com"
},
{
"firstName": "Henri",
"lastName": "Ernser",
"createdAt": "2016-05-21T11:51:54.581Z",
"location": {
"lat": 52,
"lng": -0.74853,
"lastUpdated": "2016-04-28T21:15:26.786Z"
},
"company": "Gleason, Dickens and Cassin",
"jobTitle": "Lead Data Consultant",
"email": "Henri.Ernser@ila.org"
}
]
现在,我想从location.lng&创建point
个对象。 location.lat字段,然后删除lat和lng字段,因此location字段现在看起来像这样
"location": {
"point": -0.74853, 52,
"lastUpdated": "2016-04-28T21:15:26.786Z"
},
我正在从一个文件导入,据我所知,在文档中,没有办法直接从文件导入使用ReQL,所以我必须从命令行导入然后修改导入后的每个文档。
关于如何进行上述操作的任何指示?
答案 0 :(得分:0)
这个命令足够接近我需要的
r.db('test').table('people').update(function(item) {
return {
location: {
geometry : r.point(
item("location")("lng"),
item("location")("lat")),
lastUpdated : item("location")("lastUpdated"),
lat: r.literal(),
lng: r.literal()
}
}
})
会产生类似
的位置对象 "location": {
"geometry": {
"$reql_type$": "GEOMETRY" ,
"coordinates": [-0.94645 ,51] ,
"type": "Point"
} ,
"lastUpdated": "2016-05-04T01:38:48.786Z"
}