Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var CommentSchema = mongoose.Schema({
- body: String,
- created: {
- by: {
- type: String,
- required: true
- },
- date: {
- type: Date,
- default: Date.now
- }
- }
- });
- var BlogSchema = mongoose.Schema({
- title: String,
- blog: String,
- created: {
- by: {
- type: String,
- required: true
- },
- date: {
- type: Date,
- default: Date.now
- }
- },
- comments: [CommentSchema]
- });
- var Blog = mongoose.model('Blog', BlogSchema);
- Blog.findOne({
- _id: id
- }, function(err, blog) {
- console.log(blog); // causes toJSON to be executed
- });
- // outputs:
- {
- title: 'My first blog! #Super',
- blog: 'This is my very first #blog! I hope you enjoy it. #WOOHOO',
- _id: 532cb63e25e4ad524ba17102,
- __v: 0,
- comments: [], // SHOULD THIS BE INCLUDED??
- created: {
- by: 'Joe',
- date: Fri Mar 21 2014 17: 59: 26 GMT - 0400(EDT)
- }
- }
- Blog.findOne({
- _id: id
- }, 'title', function(err, blog) {
- console.log(blog); // causes toJSON to be executed
- });
- // outputs:
- {
- title: 'My first blog! #Super',
- _id: 532caa3841176afb4a7c8476,
- created: {} // SHOULD THIS BE INCLUDED??
- }
- Blog.findOne({
- _id: id
- }, 'title', function(err, blog) {
- console.log(JSON.parse(JSON.stringify(blog))); // causes toJSON to be executed
- });
- // outputs:
- {
- title: 'My first blog! #Super',
- _id: 532caa3841176afb4a7c8476
- }
- Blog.findOne({
- _id: id
- }, function(err, blog) {
- console.log(JSON.parse(JSON.stringify(blog))); // causes toJSON to be executed
- });
- // outputs:
- {
- title: 'My first blog! #Super',
- blog: 'This is my very first #blog! I hope you enjoy it. #WOOHOO',
- _id: 532cb63e25e4ad524ba17102,
- __v: 0,
- comments: [], // SHOULD THIS BE INCLUDED??
- created: {
- by: 'Joe',
- date: Fri Mar 21 2014 17: 59: 26 GMT - 0400(EDT)
- }
- }
Add Comment
Please, Sign In to add comment