I'm trying to check if a value exists in my rethinkdb table.
It seams like its giving 2 responses.
I do it this way:
router.param('gamename', function(req, res, next, gamename) {
// do validation on gamename here
console.log(gamename);
r.table("Game").filter({
name: gamename,
}).count().eq(1)
.run()
.then(function(response){
if (response) {
console.log('Success ',response);
req.gamename = gamename;
next();
}else{
console.log("Does game exist? : "+response);
res.render('error', { gamename: gamename, message: "Game does not exist" });
}
})
.error(function(err){
console.log('error occurred ',err);
//res.render('error', { });
})
});
For some reason, if I use a gamename
that exists in the table, I get both console.log outputs, from both if and else.
NAMETHATEXISTSINTABLE
Success true
Does game exist? : false
If I use a value that does not exist I get the same twice:
NAMETHATDOESNOTEXIST
Does game exist? : false
Does game exist? : false
Why does it seam like this is run twice? One where the response is always false and the other where it is using my gamename parameter and responding true or false correctly.
Any help will be very appreciated!