Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added simple mongoose example to the boilerplate #21

Open
wants to merge 2 commits into from

1 participant

@edlau

Included changes to include sample code to cover linking to mongoose. I've also added a simple Post and Comment Schema to get things started.

Ed Lau added some commits
Ed Lau Included sample code on how to link the boilerplate with mongoose.
Also included a simple Post and Comment schema for demonstration.
0af374a
Ed Lau Included an sample schema for Mongo 6ce0e55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 20, 2012
  1. Included sample code on how to link the boilerplate with mongoose.

    Ed Lau authored
    Also included a simple Post and Comment schema for demonstration.
  2. Included an sample schema for Mongo

    Ed Lau authored
This page is out of date. Refresh to see the latest.
View
1  initproject.sh
@@ -22,6 +22,7 @@ cp ./templates/views/index.jade ./views/index.jade
cp ./templates/views/layout.jade ./views/layout.jade
cp ./templates/js/script.js ./static/js/script.js
# TODO copy over the models
+cp ./templates/models/post.js ./models/post.js
echo "Setting up the dependancies from NPM..."
npm install
View
3  templates/app/package.json
@@ -8,7 +8,8 @@
"express": "2.5.2",
"jade": "0.20.0",
"mongoose": "2.4.8",
- "socket.io": "0.8.7"
+ "socket.io": "0.8.7",
+ "walk" : "2.0.2"
},
"devDependencies": {
"vows": "0.5.x",
View
6 templates/app/server.js
@@ -2,6 +2,7 @@
var connect = require('connect')
, express = require('express')
, io = require('socket.io')
+ , mongoose = require('mongoose')
, port = (process.env.PORT || 8081);
//Setup Express
@@ -50,6 +51,11 @@ io.sockets.on('connection', function(socket){
});
});
+//Setup Mongoose
+var Schema = mongoose.Schema;
+var ObjectId = Schema.ObjectId;
+require('./models/post.js').make(Schema, mongoose);
+var db = mongoose.connect('mongodb://localhost/boilerplate');
///////////////////////////////////////////
// Routes //
View
22 templates/models/post.js
@@ -0,0 +1,22 @@
+
+// Schema
+function make(Schema, mongoose) {
+
+ CommentSchema = new Schema({
+ body : { type: String }
+ , created : { type: Date, default: Date.now }
+ });
+ mongoose.model('Comment', CommentSchema);
+
+ PostSchema = new Schema({
+ title : { type: String, default: 'New Post' }
+ , body : { type: String }
+ , created : { type: Date, default: Date.now }
+ , updated : { type: Date, default: Date.now }
+ , comments: [CommentSchema]
+ });
+ mongoose.model('Post', PostSchema);
+}
+
+module.exports.make = make;
+
Something went wrong with that request. Please try again.