Created
January 10, 2016 04:42
-
-
Save sumn2u/591560e0b72c5f5de649 to your computer and use it in GitHub Desktop.
connecting database
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
var mongoose = require('mongoose'); | |
//setup the url for the connection | |
mongoose.connect('mongodb://localhost/list'); | |
//create a connection | |
var db = mongoose.connection; | |
//if there is an error when logging in , print it | |
db.on('error', function(err){ | |
console.log(err); | |
}); | |
db.once('open', function(){ | |
//The database was successfully connected | |
console.log("connection successful"); | |
}); | |
//Define the schema for the collection | |
var listEntrySchema = mongoose.Schema({ | |
task:String, | |
status:Number | |
}); | |
//Complie the listEntrySchema into a model and export it | |
exports.ListEntry = mongoose.model('ListEntry',listEntrySchema); | |
// var newEntry = new ListEntry({ | |
// task:'Freger', | |
// status:0 | |
// }).('error', function(err){ | |
// console.log(err); | |
// }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment