Created
December 13, 2010 07:51
-
-
Save dominictarr/738770 to your computer and use it in GitHub Desktop.
hello_mongoose.js
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').Mongoose | |
mongoose.model('User', { properties: ['name'] }) | |
var db = mongoose.connect('mongodb://localhost/db'); | |
db.addListener('error',function (error){ | |
throw error | |
}) | |
var User = db.model('User'); | |
var u = new User(); | |
u.name = 'John'; | |
u.save(function(){ | |
console.log('Saved!'); | |
User.find().first(function(array){ | |
console.log(array) | |
}); | |
}); | |
/*output is: | |
Saved! | |
{ __doc: | |
{ name: null, | |
_id: { id: 'M\u0005q\\ä|\u0005\u0005\u0007\u0000\u0000\u000b' } }, | |
isNew: false, | |
_dirty: {}, | |
_partials: { _id: '"4d05715ce47c05050700000b"', name: 'null' } } | |
but no name: 'John' ? | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment