diff options
4 files changed, 18 insertions, 6 deletions
diff --git a/_posts/2011-4-22-nodejs-restify-mongodb-mongoose.textile b/_posts/2011-4-22-nodejs-restify-mongodb-mongoose.textile index 241ffd6..3b38fac 100644 --- a/_posts/2011-4-22-nodejs-restify-mongodb-mongoose.textile +++ b/_posts/2011-4-22-nodejs-restify-mongodb-mongoose.textile @@ -100,6 +100,8 @@ function getMessages(req, res, next) { // This headers comply with CORS and allow us to server our response to any origin res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "X-Requested-With"); + // .find() without any arguments, will return all results + // the `-1` in .sort() means descending order Message.find().sort('date', -1).execFind(function (arr,data) { res.send(data); }); @@ -125,6 +127,14 @@ server.post('/messages', postMessage); {% endhighlight %} +This wraps up the server side of things, if you follow the "example":https://github.com/thomasdavis/backbonetutorials/blob/gh-pages/examples/nodejs-mongodb-mongoose-restify/server.js then you should see something like + +"http://backbonetutorials.nodejitsu.com/messages":http://backbonetutorials.nodejitsu.com/messages + + +Note: Again you must remember to change the "Model":https://github.com/thomasdavis/backbonetutorials/blob/gh-pages/examples/nodejs-mongodb-mongoose-restify/js/models/message.js and "Collection":https://github.com/thomasdavis/backbonetutorials/blob/gh-pages/examples/nodejs-mongodb-mongoose-restify/js/collections/messages.js definitions to match your server address. + +Inside of our function definitions we have used our Mongoose model to perform the appropiate action. Note: We have created a shortcut to Mongooses Schema variable. Mongoose makes some of the typical MongoDb paradigms easier to implement and understand. diff --git a/examples/nodejs-mongodb-mongoose-restify/js/collections/messages.js b/examples/nodejs-mongodb-mongoose-restify/js/collections/messages.js index 1edaa0a..59d32db 100644 --- a/examples/nodejs-mongodb-mongoose-restify/js/collections/messages.js +++ b/examples/nodejs-mongodb-mongoose-restify/js/collections/messages.js @@ -6,7 +6,8 @@ define([ ], function($, _, Backbone, MessageModel){ var Messages = Backbone.Collection.extend({ model: MessageModel, - url: 'http://localhost:8080/messages' + //url: 'http://localhost:8080/messages' + url: 'http://backbonetutorials.nodejitsu.com/messages' }); return Messages; diff --git a/examples/nodejs-mongodb-mongoose-restify/js/models/message.js b/examples/nodejs-mongodb-mongoose-restify/js/models/message.js index d61d447..19b15d2 100644 --- a/examples/nodejs-mongodb-mongoose-restify/js/models/message.js +++ b/examples/nodejs-mongodb-mongoose-restify/js/models/message.js @@ -3,7 +3,8 @@ define([ 'backbone' ], function(_, Backbone) { var Message = Backbone.Model.extend({ - url: 'http://localhost:8080/messages' + //url: 'http://localhost:8080/messages' + url: 'http://backbonetutorials.nodejitsu.com/messages' }); return Message; }); diff --git a/examples/nodejs-mongodb-mongoose-restify/package.json b/examples/nodejs-mongodb-mongoose-restify/package.json index 522b0ba..6de9aaf 100644 --- a/examples/nodejs-mongodb-mongoose-restify/package.json +++ b/examples/nodejs-mongodb-mongoose-restify/package.json @@ -1,10 +1,10 @@ { - "name": "budder", - "subdomain": "budder", + "name": "backbonetutorials", + "subdomain": "backbonetutorials", "scripts": { "start": "server.js" }, - "version": "0.0.0-8", + "version": "0.0.0-9", "engines": { "node": "0.6.x" }, @@ -12,4 +12,4 @@ "restify": "1.4.x", "mongoose": "2.6.x" } -}
\ No newline at end of file +} |