kjames
kjames

Reputation: 656

Accessing nested fields with Rethinkdb

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"

Upvotes: 1

Views: 122

Answers (1)

Wow
Wow

Reputation: 20

use this:

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

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

});

Upvotes: 0

Related Questions