Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ####################
- ## models/blog.js ##
- ####################
- var mongoose = require('mongoose')
- , Schema = mongoose.Schema;
- var util = require('util');
- var ArticleSchema = new Schema({
- title : { type: String, index: true }
- , content : { type: String }
- , date : { type: Date, default: Date.now }
- //, comments : [Comment]
- });
- var ArticleModel = mongoose.model('Article', ArticleSchema);
- //exports.Article = mongoose.model('Article', ArticleSchema);
- exports.Article = ArticleModel;
- exports.Articles = ArticleModel.find({}, function(err, doc){
- if(err){
- console.log('Error: '+"\n"+util.inspect(err)+"\n");
- return err;
- } else {
- console.log('Document: '+"\n"+util.inspect(doc)+"\n");
- return doc;
- }
- });
- ##############
- ## resource ##
- ##############
- // GET /blog
- exports.index = function(req, res){
- var articles = require('../models/blog').Articles;
- console.log(util.inspect(articles, true, 3)+"\n");
- switch(req.format){
- case 'json':
- res.send(util.inspect(articles));
- break;
- case 'xml':
- res.send('<article>' + articles.map(function(article){
- return '<article_title>' + article.title + '</article_title>';
- }).join('') + '</article>');
- break;
- default:
- //res.send(articles);
- res.render('blog', {
- locals: {
- title: 'Blog',
- articles: articles
- }
- });
- }
- };
- ####################
- ## Console Output ##
- ####################
- { _conditions: {},
- op: 'find',
- options: { populate: {} },
- model:
- { [Function: model]
- [arguments]: null,
- modelName: 'Article',
- [length]: 0,
- [name]: 'model',
- [prototype]:
- { base:
- { Connection: [Object],
- Collection: [Object],
- Query: [Object],
- Error: [Object],
- Model: [Object],
- mongo: [Object],
- Mongoose: [Object],
- VirtualType: [Object],
- Document: [Object],
- Types: [Object],
- plugins: [Object],
- connections: [Object],
- modelSchemas: [Object],
- Schema: [Object],
- options: {},
- SchemaType: [Object],
- version: '2.0.4',
- SchemaTypes: [Object],
- models: [Object],
- Promise: [Object] },
- _schema:
- { callQueue: [Object],
- statics: {},
- tree: [Object],
- _indexes: [Object],
- options: [Object],
- virtuals: [Object],
- inherits: {},
- methods: {},
- paths: [Object] },
- db:
- { base: [Object],
- db: [Object],
- readyState: 1,
- host: 'localhost',
- options: [Object],
- pass: undefined,
- name: 'aps-test',
- models: {},
- collections: [Object],
- port: 27017,
- user: undefined },
- id: [Getter/Setter],
- date: [Getter/Setter],
- collection:
- { queue: [Object],
- name: 'articles',
- collection: [Object],
- conn: [Object],
- buffer: false },
- title: [Getter/Setter],
- content: [Getter/Setter],
- _id: [Getter/Setter],
- [constructor]: [Circular] },
- [caller]: null },
- safe: undefined }
- Document:
- [ { title: 'Hidey Ho',
- content: 'Neighbor!',
- _id: 4e5eb0a16f08824824000001,
- date: Wed, 31 Aug 2011 22:07:29 GMT } ]
- 127.0.0.1 - - [Wed, 31 Aug 2011 22:32:45 GMT] "GET /favicon.ico HTTP/1.1" 404 - "-" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.218 Safari/535.1"
Add Comment
Please, Sign In to add comment