I'm learning Node.js + mongodb using a simple tutorial - the problem is that I can't get it to save().
This is the code I'm running:
mongoose = require('mongoose'),
Schema = mongoose.Schema;
PostSchema = new Schema({
title: String,
body: String,
date: Date
});
mongoose.connect('mongodb://localhost/posterdb');
mongoose.model('Post', PostSchema);
var Post = mongoose.model('Post');
// create a post and save it
var post = new Post();
post.title = 'My first post';
post.body = 'Post body';
post.date = Date.now();
post.save(function(err) {
console.log('error check');
if(err) { throw err; }
console.log('saved');
mongoose.disconnect();
});
It doesn't print anything on the console. Any ideas?
mongoose.connection.on("open", function() { ... }).