如何在 RethinkDB 中通过嵌套值查询文档?

How do I query a document by a nested value in RethinkDB?

ReThinkDB docs提及:

Documents can be filtered in a variety of ways—ranges, nested values, boolean conditions, and the results of anonymous functions.

假设我有:

{
  name: 'Joe'
  orders: [
    {
      id: 123456,
      date: '2016-01-19T09:12:48.898000+00:00'
    }
  ]
}

我想检索订单中有 id 为 123456 的订单的用户

根据 the docs,我尝试使用...

(long list of things cut out, now I've found the actual answer)

但是我没有得到结果。

知道了:

r.db('myapp').table('people').filter(function(person){
  return person("orders").contains(function (order) {
    return order('id').eq(123456);
  })
})

这也有效:

r.db('myapp').table('people').filter(function(person) {
  return person('orders').map(function(order){ 
    return order('id')
  }).contains(123456)
})