Created
March 26, 2014 20:04
-
-
Save tmlbl/9791989 to your computer and use it in GitHub Desktop.
Mongoose nested model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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