Search code examples
javascriptnode.jsrethinkdbrethinkdb-javascript

Listen change feed of complex queries in RethinkDB


When i have a query like this:

r.db('universe')
  .table('Star')
  .getAll(
    r.db('universe').table('Ship').get(idShip)('idCurrentGalaxy'),
    {index: 'idGalaxy'}
  )
  .changes({includeInitial: true})

I expect it to update the changefeed when

  1. a selected star gets updated
  2. the selected ship.idCurrentGalaxy changes

With this query, only 1. is true. If it is possible, how can i change this query to make 2. also true?

The data behind the query could be something like this:

//stars
{id: 1, idGalaxy: 1, name: 'Aldhafera'}
{id: 2, idGalaxy: 1, name: 'Duhr'}
{id: 3, idGalaxy: 2, name: 'Menchib'}

//galaxies
{id: 1, name: 'Milky Way'}
{id: 2, name: 'Andromeda'}

//ships
{id: 1, idCurrentGalaxy: 1}

and the query above would result this:

{id: 1, idGalaxy: 1, name: 'Aldhafera'}
{id: 2, idGalaxy: 1, name: 'Duhr'}

Solution

  • There's currently no way to get that in RethinkDB; you have to open two changefeeds and stitch them together yourself. Support for this will eventually be added; you can track progress at https://github.com/rethinkdb/rethinkdb/issues/3997 .