Skip to content

Instantly share code, notes, and snippets.

@tmlbl
Created March 26, 2014 20:04
Show Gist options
  • Save tmlbl/9791989 to your computer and use it in GitHub Desktop.
Save tmlbl/9791989 to your computer and use it in GitHub Desktop.
Mongoose nested model
module.exports = function (Schema, mongoose) {
var CommentSchema = new Schema({
author : { type: String },
postdate : { type: Date, default: Date.now() },
body : { type: String }
});
var PostSchema = new Schema({
title : { type: String, required: true },
url : { type: String, required: true, unique: true },
postdate : { type: Date, default: Date.now() },
body : { type: String },
comments : [ CommentSchema ]
});
return mongoose.model('Post', PostSchema);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment