Accessing nested fields with Rethinkdb

117 Views Asked by At

So I have a result that looks like this

"data": {
  "randomkeyllasdkjflk": {
     "name": "John Doe"
  },
  "anotherrandomkeyadf": {
     "name": "Mona Lee"
  }
}

and I want to access the name.

This is what I tried:

r.table('users').filter(function (doc) {

      return doc('data').coerceTo('array').map(function(ref) {
        return ref('name')
      }).contains("John")

    });

But will produce an error that says:

e: Cannot perform bracket on a non-object non-sequence "randomkeyllasdkjflk"

1

There are 1 best solutions below

0
Wow On BEST ANSWER

use this:

r.table('users').filter(function (doc) {

  return doc('data').keys().map(function(ref) {
    return doc('data')(ref)('name')
  }).contains("John")

});