Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var validateUser = function(userName, password, callback){
- const MongoClient = require('mongodb').MongoClient;
- // replace the uri string with your connection string.
- const uri = "mongodb+srv://CarlosHz:BlackjackSeng513@blackjack-2j9ms.mongodb.net/test?retryWrites=true";
- MongoClient.connect(uri, function(err, client) {
- if(err) {
- console.log('Error occurred while connecting to MongoDB Atlas...\n',err.stack);
- }else{
- console.log('Connected...');
- const db = client.db("Blackjack");
- const collection = db.collection("Users");
- collection.findOne({username: userName}, (function(err, result){
- if(err){
- console.log("error in find");
- }else if(result != null){
- console.log("success find function");
- console.log(result.username + " " + result.password + " was found");
- if(result.username === userName && result.password === password){
- console.log("returning true");
- return callback(true);
- }else{
- console.log("returning false");
- return callback(false);
- }
- }else{
- console.log("user does not exists");
- console.log("returning false");
- return callback(false);
- }
- }));
- client.close();
- //collection.insertOne( {username: "poop", password: "wtfisthis"});
- //var query = { username: "poop" };
- //var newval = { $set: {balance: 500 }};
- //collection.updateOne(query, newval, function(err, res){
- // if(err){
- // console.log("error");
- // }else{
- // console.log("success");
- // }
- // perform actions on the collection object
- //client.close();
- }
- });
- }
Add Comment
Please, Sign In to add comment