Skip to content

Instantly share code, notes, and snippets.

@sumn2u
Created January 10, 2016 04:42
Show Gist options
  • Save sumn2u/591560e0b72c5f5de649 to your computer and use it in GitHub Desktop.
Save sumn2u/591560e0b72c5f5de649 to your computer and use it in GitHub Desktop.
connecting database
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