Created
June 24, 2014 22:33
-
-
Save geastwood/161a73974210c3a5f5b3 to your computer and use it in GitHub Desktop.
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
/* | |
* Mongoose magic | |
*/ | |
var mongoose = require('mongoose'); | |
mongoose.connect('mongodb://localhost:27017/fei'); | |
var db = mongoose.connection; | |
db.on('error', console.error.bind(console, 'connection error')); | |
db.once('open', function() { | |
var kittySchema = mongoose.Schema({ | |
name: String | |
}); | |
kittySchema.methods.speak = function() { | |
console.log('meow'); | |
}; | |
var Kitten = mongoose.model('Kitten', kittySchema); | |
var fluffy = new Kitten({name: 'fluffy'}); | |
var boot = new Kitten({name: 'boot'}); | |
fluffy.save(function(err, fluffy) { | |
fluffy.speak(); | |
}); | |
boot.save(function(err, boot) { | |
boot.speak(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment