bchavez / RethinkDb.Driver

:headphones: A NoSQL C#/.NET RethinkDB database driver with 100% ReQL API coverage.
http://rethinkdb.com/api/java
Other
384 stars 134 forks source link

Changefeed on more than one table #101

Closed alana1 closed 8 years ago

alana1 commented 8 years ago

Hello,

I am using the RethinkDB C# driver version 2.3.14.0 with RethinkDB for windows 2.3.4. I am listening on two table changfeed on the same class. Each table have different json properties. I am using Reactive observable to get changefeed OnNext event. All of the changfeed events from the two tables go to the same OnNext event handler. Is there a way I can have unique changefeed events for each changefeed listener? I have I am making sense here.

bchavez commented 8 years ago

So I'm not sure if sending two changefeeds into the same class as the right thing to do mostly because you could run into some multi-threading issues with your class that's handling OnNext.

However, with that said, you could do the following:

r.db("mydatabase").table("table1").changes().merge({changefeedID: "ThisChangeIsFromTable1"})

And a change on table one, like an insert, would produce the following:

{
  "changefeedID":  "ThisChangeIsFromTable1" ,
  "new_val": {
    "hello":  "world" ,
    "id":  "d9b3873b-a7df-49e6-b878-19ec37dfd941"
  } ,
  "old_val": null
}

changefeedID would be merged into a change event. I'm guessing all you'd need to do is put an if statement to branch on the change event coming in from different tables.

I'm going to close the issue since this issue is more of a help question rather than a bug report or request to change the source code in the repository. If you need more help I should be available on slack / @bchavez.

Thanks,

:dancers: :dancer: _"Ich zeig Dir wie ich tanz... Komm lass uns geh'n..."_