Permalink
Browse files

Merge branch 'master' of github.com:NebTeam/InnovationDay-Nodejs

  • Loading branch information...
2 parents 60bc49b + 3bcc68c commit e5842dc442ee1af01e988e1d18c4f1a9c31533a9 @DannyDouglass DannyDouglass committed Mar 9, 2012
Showing with 25 additions and 13 deletions.
  1. +25 −13 app.js
View
38 app.js
@@ -3,30 +3,42 @@ var express = require('express');
var app = express.createServer();
+var mongoose = require('mongoose');
+
+var Schema = mongoose.Schema
+ , ObjectId = Schema.ObjectId;
+
// Configuration
app.configure( function() {
});
+var MessageSchema = new Schema({
+ sender : { type: String, default: 'hahaha' }
+ , receiver : { type: String, min: 18, index: true }
+ , date : { type: Date, default: Date.now }
+});
+
+// var MessageModel = mongoose.model('Message', MessageSchema);
+
// Routes
app.get('/', function(req, res) {
- var Db = require('mongodb').Db;
- var Connection = require('mongodb').Connection;
- var Server = require('mongodb').Server;
- var BSON = require('mongodb').BSON;
- var ObjectID = require('mongodb').ObjectID;
-
- //res.write('pre open conn');
+ var conn = mongoose.createConnection('mongodb://localhost/innovation-day-nodejs');
+ var MessageModel = conn.model('ModelName', MessageSchema);
+ var m = new MessageModel;
- db= new Db('innovation-day-nodejs', new Server('localhost', 27017, {auto_reconnect: true}, {}));
- db.open(function(){});
+ m.sender = 'Danny';
+ m.receiver = 'Chernacov';
+ m.date = new Date();
- //res.write('opened conn');
+ m.save(function(e, message) {
+ console.log(message);
- var messages = db.collection('message', function(error, message_collection) {
- res.send(message_collection);
+ // why in the hell doesn't this work?
+ MessageModel.find({}).each(function(doc){
+ console.log(doc);
+ });
});
- //res.send([{ first : 'hist' }]);
res.end();
});

0 comments on commit e5842dc

Please sign in to comment.