0

RethinkDB newb here and I can't figure this one out.

Lets say I have a table named mydata with documents that have the following basic structure:

{
    "SomeAttirbute": "SomeValue",
    "team": [
        {
            "name":  "john" ,
            "other": "stuff",
        } ,
        {
            "name":  "jane" ,
            "other": "junk",
        }
    ] ,
    ...
}

How do I get all documents in the mydata table that have john for a value of the name attribute for any of the elements in the team array?

jay
  • 53
  • 1
  • 5

2 Answers2

0

This is pretty easy and requires a simple ReQL expression. In JavaScript it would be something like this:

const name = 'john';

...

r.db('q50732045')
  .table('mydata')
  // The predicate below can be literally read as:
  //     a document whose `team` property is a sequence
  //     that contains any element with a property `name`
  //     that equals the given name
  .filter(doc => doc('team').contains(member => member('name').eq(name)))
  // No need to invoke the run method in Data Explorer
  ;

I do believe it can be easily re-written in Python.

Lyubomyr Shaydariv
  • 20,327
  • 12
  • 64
  • 105
0

I think this is what you are looking for:

r.db(insert_database_name).table("mydata").filter(
    lambda doc: doc["team"]["name"].contains("john")
).run(con)

or:

r.db(insert_database_name).table("mydata").filter(
    r.row["team"]["name"].contains("john")
).run(con)
Platos-Child
  • 324
  • 1
  • 6