0

I have a problem with the changelog function of rethinkdb. There is no console output, when adding a document to the collection. BUT "changes" is outputted once after starting my application via node app.js, why is that so? Any help is appreciated.

// rethinkdb connection
var connection = null;
r.connect({ db: 'bc', host: 'localhost', port: 1337}, function(err, conn) {
    if(err) throw err;

    connection = conn;
    observeBets();
});


function observeBets() {
    r.table('bets').changes().run(connection, function(err, betsCursor) {
        if (err) throw err;

        console.log("changes");
    });
}

Insert via

var bet = {
    bet: "test",
    userID: 213
};
r.table('bets').insert(bet);
Chris
  • 4,255
  • 7
  • 42
  • 83
  • Running the changes() query via the Data Explorer works as expected, so there must be a node problem I guess. – Chris Mar 19 '16 at 17:33

1 Answers1

1

I think you need to be iterating over betsCursor.

mlucy
  • 5,249
  • 1
  • 17
  • 21
  • But why? Isnt it just a callback function which should be called thus `console.log ("changes")` should be called? – Chris Mar 20 '16 at 09:40
  • The callback isn't called once per change, it's called once when you've *finished subscribing to changes*, and it's passed a cursor. If you call `bestCursor.each(callback2)`, then `callback2` will be called for every change. – mlucy Mar 20 '16 at 19:07