Last active
May 4, 2017 02:38
-
-
Save ma-he-sh/c959f5639e4271374bc171cd1414a07b to your computer and use it in GitHub Desktop.
Rethinkdb check whether user exists and if not insert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var email = '[email protected]'; | |
r.db('dbname').table('users') | |
.get(email) | |
.run() | |
.then(function (response) { | |
if (response == null) { | |
//console.log('User Not exists'); | |
//insert user data | |
r.db('dbname').table('users').insert({ | |
'email': email, | |
'Uname': uname, | |
'Fname': fname, | |
'Lname': lname, | |
password: hash | |
}).run(); | |
res.redirect('/signup'); | |
} | |
else { | |
//user exists | |
console.log(response); | |
res.redirect('/signup'); | |
} | |
}) | |
.catch(function (err) { | |
//parse the error | |
console.log(err); | |
res.redirect('/signup'); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment