0
4

1 回答 1

2

你实际上做得对,几乎就在那里。您只是碰巧使用filter了错误的键。

r.db('myDb').table('myTable').getNearest(r.point(-20, 39), {index: 'location'})
    .filter(function(user) {
           return user('doc')('id').ne('2ff8902e-97f0-431a-a51c-900a57532967')
    })

关键是:

  1. getNearest返回一个文档数组。每个文档都有两个字段:distdoc(它是表本身的文档)。因此,我们在这里使用user('doc')('id')来获取密钥。 https://rethinkdb.com/api/javascript/get_nearest/
  2. filter函数内部,我们必须使用 ReQL 命令,在这种情况下,ne均值,不等于。https://www.rethinkdb.com/api/javascript/ne/

这很快,因为我们在位置上有索引。并且filter函数在 RethinkDB 服务器上执行。

于 2015-10-21T19:16:47.043 回答