Created
July 9, 2015 04:44
-
-
Save AndyNovo/a167f48940a3d3cab326 to your computer and use it in GitHub Desktop.
To play with mongoose and mongo in CISC437
This file contains hidden or 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'); | |
var db = mongoose.connection; | |
db.on('error', console.error); | |
db.once('open', function(){ | |
var studSchema = new mongoose.Schema({ | |
name: String | |
}, { strict: false }); | |
var Student = mongoose.model('Student', studSchema, 'student'); | |
Student.remove({name: "Novocin4"}, function(err){ if (err) console.error(err);}); | |
Student.findOne({name: "Novocin2"}, function(err, student){ | |
if (err) return console.error(err); | |
console.log(student); | |
if (student){ | |
student.name = "Novocin4"; | |
student.save(function(err, student4){ console.log("saved"); }); | |
} | |
}); | |
var newstud = new Student({ | |
name: "Novocin2", | |
ID: "31415", | |
dept_name: "Math", | |
skills: ["dancing", "singing"] | |
}); | |
newstud.save(function(err, student){ | |
if (err) return console.error(err); | |
console.log("Adding new student: "); | |
console.log(student); | |
}); | |
}); | |
mongoose.connect('mongodb://localhost/uni'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment