Search code examples
rethinkdbrethinkdb-javascript

Query nested field with index support


Can anyone tell me is there a way to query nested field with index support. I created nested index like: r.table('comments').indexCreate('authorName', r.row("author")("name")).run(conn, callback) but I can't see any ways to query all comments which have specified author name - documentations says that getAll command takes number, string, bool, pseudotype, or array and filter command does not currently have an optimizer for indexes


Solution

  • I've just tried creating a nested r.row("author")("name") secondary index named "authorName" for a table with the following rows:

    [
      {
        "author": {
          "name":  "Lennon"
        },
        "text":  "c1",
        "id":  "4f66dcac-be74-49f2-b8dc-5fc352f4f928"
      },
    
      {
        "author": {
          "name":  "Cobain"
        },
        "text":  "c2",
        "id":  "82936ae0-bc4d-435b-b19a-6786339da232"
      }
    ]
    

    It seems that

    r.table('comments').getAll("Cobain", {index: "authorName"}).run(conn, callback)
    

    is working and returns

      {
        "author": {
          "name":  "Cobain"
        },
        "text":  "c2",
        "id":  "82936ae0-bc4d-435b-b19a-6786339da232"
      }