Created
March 14, 2011 19:16
Revisions
-
wereHamster created this gist
Mar 14, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ var mongoose = require('../lib/mongoose') mongoose.connect('mongodb://localhost/test'); var Document = null, DocumentSchema = new mongoose.Schema({ data: { type: String }, }); DocumentSchema.pre('init', function(next) { console.log('pre-init: ' + JSON.stringify(this)); next(); }); DocumentSchema.post('init', function() { console.log('post-init: ' + JSON.stringify(this)); }); DocumentSchema.method({ fubar: function(hint) { console.log(hint + ': ' + JSON.stringify(this)); }, }); mongoose.model('Document', DocumentSchema); Document = mongoose.model('Document'); var doc = new Document({ data: 'this is a document' }); doc.fubar('fresh document'); doc.save(function(err) { Document.findById(doc._id, function(err, doc) { doc.fubar('from database'); }); })