0

i have a table notifications. records are inserted as so:

socket.on('set notif',function(data){
    var user = socket.client.user;
    if(typeof user !== 'object' && user == '_srv'){
        r.table('notifications').insert(data).run().then(function(res){
            r.table('notifications').get(res.generated_keys[0]).run().then(function(data){
                var user = data.user_id;
                io.sockets.in(user).emit('new notif',data);
            });
        });
    }
});

when a meeting is declined by a user, we must delete all associated meeting notifications and send a notification with a null meeting_id to the user notifying them that the other party has declined their offer.

socket.on('del meeting notifs',function(data){
    var user = socket.client.user;
    if(typeof user !== 'object' && user == '_srv'){
        r.table('notifications').getAll(data.id,{index:'meeting_id'}).delete().run().then(function(){

        });
    }
});

instead, all notifications in the table seem to be deleted, and im not sure why. is there a problem with my query? i'm finding it really difficult to grasp the syntax of rethinkdb. I am using rethinkdb-dash library but stackoverflow won't allow me to tag this question as such.

r3wt
  • 4,642
  • 2
  • 33
  • 55
  • Have you tried using `.filter()` instead of `.getAll()`? – CCates Feb 23 '16 at 03:18
  • If you run `r.table('notifications').getAll(data.id, {index: 'meeting_id'}).count()`, does it return a different number from `r.table('notifications').count()`? If not, then the problem is that all your data has the same meeting ID. – mlucy Feb 23 '16 at 21:00

0 Answers0