0

I'm importing data from a file into Rethinkdb.

the data looks like this (this is fake data)

[
  {
    "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"
  }
]

Now, I want to create point objects from the location.lng & location.lat fields, and then remove the lat, and lng fields, so the location field would now look like this

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

I'm importing from a file, and as far as i can tell in the docs, there is no way to import directly from a file using ReQL, so i would have to do the import from the command line and then modify each document after the import.

Any pointers on how to go about doing the above?

MrBliz
  • 5,830
  • 15
  • 57
  • 81

1 Answers1

0

This command is close enough to what i needed

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()
    }
  }

})

which results in a location object like

    "location": {
        "geometry": {
            "$reql_type$":  "GEOMETRY" ,
             "coordinates": [-0.94645 ,51] ,
             "type":  "Point"
         } ,
         "lastUpdated":  "2016-05-04T01:38:48.786Z"
     }
MrBliz
  • 5,830
  • 15
  • 57
  • 81