2016-05-31 26 views
0

我正在將數據從文件導入到Rethinkdb中。從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": "[email protected]" 
    }, 
    { 
    "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": "[email protected]" 
    } 
] 

現在,我想從location.lng & location.lat領域創造point對象,然後取出LAT和液化天然氣領域,所以場上的位置,現在看起來像這樣

"location": { 
      "point": -0.74853, 52, 
      "lastUpdated": "2016-04-28T21:15:26.786Z" 
     }, 

我從文件導入,並儘可能我可以在文檔中告訴,有沒有辦法直接使用ReQL要導入的文件,所以我將不得不從命令行和T進行導入在導入後修改每個文檔。

關於如何去做上述任何指針?

回答

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" 
    }