0
Cursor changeCursor = r.table(Hardcoded.rethinkDBTableName()).changes().getField("new_val").without("id").run(conn);
    for (Object change : changeCursor) {
        System.out.println(change);
    }

RESULT:

{  
   askPrice=1.29846,
   symbol=EUR/USD,
   bidTime=1455800529000,
   askTime=1455800529000,
   bidSize=1,
   askSize=1,
   bidPrice=1.2984
}

EXPECTED:

{  
   "askSize":1,
   "askPrice":1.2978,
   "askTime":1455729430000,
   "bidTime":1455729430000,
   "bidPrice":1.29778,
   "symbol":"EUR/USD",
   "bidSize":1
}
Johannes Jander
  • 4,974
  • 2
  • 31
  • 46
k7i3
  • 3
  • 2
  • Is actual result exactly the same in the block which is in your question ? I mean, is that starts with "{ " and ends with "}" or you added them when you are writing the question ? – Ömer Erden Feb 18 '16 at 16:34
  • @Bolzano yes, the result is exactly the same with {...} – k7i3 Feb 18 '16 at 20:17
  • I can get static data as JSON string in this way - r.table(TABLE_NAME).get(ID).toJson().run(conn), but when i'm listening updates with adding ".changes()" - r.table(TABLE_NAME).changes().toJson().run(conn), it throw the exception - Expected type DATUM but found SEQUENCE: VALUE SEQUENCE – k7i3 Feb 18 '16 at 20:29
  • i assume toJson() method works with a single Data. its working because you are getting data with get(ID) , probably if you use get(ID) with changes() you'll get this error http://stackoverflow.com/questions/26827952/how-to-extract-multiple-queries-at-once-in-rethinkdb, so this link can help you i guess – Ömer Erden Feb 18 '16 at 21:34
  • @Bolzano Thanks for the advice but adding coerceTo("array") throw the exception - Cannot call a terminal (`reduce`, `count`, etc.) on an infinite stream (such as a changefeed) – k7i3 Feb 19 '16 at 08:09

1 Answers1

1

You can write r.table(Hardcoded.rethinkDBTableName()).changes().getField("new_val").without("id").map(val -> val.toJson()) and I think that will do what you want.

mlucy
  • 5,249
  • 1
  • 17
  • 21
  • Thank you a lot. It was very helpful for me. I resolved it on Java. Do you know how to do the same on Scala? – k7i3 Feb 20 '16 at 13:37
  • It should be the same trick except the anonymous function syntax inside the `map` will be whatever Scala's anonymous function syntax is. – mlucy Feb 21 '16 at 04:25