Created
May 24, 2017 02:22
-
-
Save anonymous/4efaa5463b332f313b74dda18c58b0e2 to your computer and use it in GitHub Desktop.
This file contains 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
(function() { | |
var Promise = require('bluebird'); | |
var mongoose = require('mongoose'); | |
var uristring = | |
process.env.MONGODB_URI || | |
'mongodb://localhost/HelloMongoose'; | |
var theport = process.env.PORT || 5000; | |
mongoose.connect(uristring, function (err, res) { | |
if (err) { | |
console.log ('ERROR connecting to: ' + uristring + '. ' + err); | |
} else { | |
console.log ('Succeeded connected to: ' + uristring); | |
} | |
}); | |
var Schema = mongoose.Schema; | |
var userSchema = new Schema({ | |
user: String, | |
username: String, | |
password: String, | |
name : String, | |
role: String | |
}); | |
var Users = mongoose.model('Users', userSchema); | |
var user = { | |
getUserByUsername: function(username) { | |
Users.find({}).exec(function (error, users) { | |
callback(users); | |
}); | |
function callback(users) { | |
console.log(users); | |
for(var i= 0; i < users.length; i++) { | |
// console.log(users[i].username); | |
if(users[i].username === username) { | |
console.log(true); | |
return users[i]; | |
} | |
} | |
} | |
} | |
}; | |
this.user = user; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment