0

I am new in Rethinkdb and the ReQL api. And I want to know what is the best way of getting the count() of a table after insert() a new row?

This is my actual javascript implementation, but I think it can be improved

r.table('likes') .changes() .run(conn) .then(cursor => cursor.each(() => { r.table('likes') .count() .run(conn, (err, result) => console.log(result)) }) })

Then when I add new row

r.table('likes') .insert({ time: (new Date()).getTime() }) .run(conn)

Thank you for your help!

Michael Rasoahaingo
  • 1,069
  • 6
  • 11
  • Why not have a change feed for count? e.g. `r.table('likes').count().changes()` – Shai Mishali May 30 '16 at 10:37
  • 1
    You cannot get the changefeed after count() unfortunately :( "However, since the stream produced by changes has no ending, commands that need to consume the entire stream before returning (such as reduce or count) cannot." (https://www.rethinkdb.com/api/javascript/changes/) – Michael Rasoahaingo May 31 '16 at 12:05

0 Answers0