You cannot pluck
an index. I think you mean field
, because the way you want to extract the data of that field with pluck
. And you create an index with same name, from that field. If my assumption is correct, below is my answer. If not, you need to update your question because you cannot pluck an index.
The problem is wrong data type. According to https://rethinkdb.com/api/javascript/distance/, command syntax looks liek this:
geometry.distance(geometry[, {geoSystem: 'WGS84', unit: 'm'}]) → number
r.distance(geometry, geometry[, {geoSystem: 'WGS84', unit: 'm'}]) → number
That means distance
can be either call on r
, passing two geometyr
object, or calling on a geometry
object, and passing another geometry object as its first parameter.
Your query is returning a STREAM. You can found out its data type via reading document of API, or just use typeOf
.
r.db('food').table('fruits')
.hasFields(['origin', 'region'])
.filter({region: 'North America'})
.pluck('gpsLocation')
.typeOf()
So, you have to somehow loop over the STREAM, and calling distance
on a document of stream.
r.db('food').table('fruits')
.hasFields(['origin', 'region'])
.filter({region: 'North America'})
.pluck('gpsLocation')
.map(function(location) {
return location.distance(r.point(37.759056, 105.015018))
})
It's a bit similar to how you have an array, and calling map
in JavaScript to walk over the array, and running a callback function on the element. Though here, the map function runs on server.
With assume that you gpsLocation
field contains an geometry
object, such as a point(https://rethinkdb.com/api/javascript/point/) with longitude and latitude.