3

The ReThinkDB docs mention:

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

Say I have:

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

And I would like to retrieve users who have an order with id 123456 in their orders

Per the docs, I have tried using...

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

But I get no results.

mikemaccana
  • 110,530
  • 99
  • 389
  • 494

2 Answers2

4

This works too:

r.db('myapp').table('people').filter(function(person) {
  return person('orders').map(function(order){ 
    return order('id')
  }).contains(123456)
})
mikemaccana
  • 110,530
  • 99
  • 389
  • 494
lukaszkorecki
  • 1,743
  • 1
  • 15
  • 19
  • @mikemaccana - I'm just exploring how to use rethinkdb and wondering, in light of this question, do you know how (or if even possible) to go about building an index on that? – thetaiko Mar 28 '17 at 13:50
  • @thetaiko Best asked as it's own question! – mikemaccana Mar 29 '17 at 15:30
0

Got it:

r.db('myapp').table('people').filter(function(person){
  return person("orders").contains(function (order) {
    return order('id').eq(123456);
  })
})
mikemaccana
  • 110,530
  • 99
  • 389
  • 494