Skip to content

Instantly share code, notes, and snippets.

@dirkk0
Created August 30, 2013 15:22
Show Gist options
  • Select an option

  • Save dirkk0/6390977 to your computer and use it in GitHub Desktop.

Select an option

Save dirkk0/6390977 to your computer and use it in GitHub Desktop.
Retreive users from mean.io database (i.e. retrieve data from mongoDB via mongoose)
//require mongoose node module
var mongoose = require('mongoose');
//connect to local mongodb database
var db = mongoose.connect('mongodb://127.0.0.1:27017/mean-dev');
//attach lister to connected event
mongoose.connection.once('connected', function() {
console.log("Connected to database")
});
var schema = new mongoose.Schema({ username: 'string' });
var Users = mongoose.model('users', schema);
var a = Users.find(function(err, users) {
mongoose.connection.close();
// console.log(users);
for (var i in users){
console.log(users[i]['username']);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment