Skip to content

Instantly share code, notes, and snippets.

@dominictarr
Created December 13, 2010 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominictarr/738770 to your computer and use it in GitHub Desktop.
Save dominictarr/738770 to your computer and use it in GitHub Desktop.
hello_mongoose.js
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