Skip to content

Instantly share code, notes, and snippets.

@ma-he-sh
Last active May 4, 2017 02:38
Show Gist options
  • Save ma-he-sh/c959f5639e4271374bc171cd1414a07b to your computer and use it in GitHub Desktop.
Save ma-he-sh/c959f5639e4271374bc171cd1414a07b to your computer and use it in GitHub Desktop.
Rethinkdb check whether user exists and if not insert
var email = 'test@email.com';
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