Create a new file named Post.js in the /models directory.
Define the following fields in the Post schema:
title: String (Required) - Title of the post.
content: String (Required) - Main content of the post.
author: Schema.Types.ObjectId (Reference to User, Required) - User who authored the post.
blob: Number (Default: 0) - Additional metadata field for future use.
media: [String] - Array of URLs or paths to media files (images, videos).
comments: [Schema.Types.ObjectId] (Reference to Comment) - Array of associated comments.
Schema Options:
Enable toJSON virtuals for the schema to transform the document data when serialized.
Create Model:
Use mongoose.model() to create the Post model from the schema.
Export Model:
Export the Post model for use in other parts of the application.
Create a new file named Post.js in the /models directory. Define the following fields in the Post schema: title: String (Required) - Title of the post. content: String (Required) - Main content of the post. author: Schema.Types.ObjectId (Reference to User, Required) - User who authored the post. blob: Number (Default: 0) - Additional metadata field for future use. media: [String] - Array of URLs or paths to media files (images, videos). comments: [Schema.Types.ObjectId] (Reference to Comment) - Array of associated comments. Schema Options:
Enable toJSON virtuals for the schema to transform the document data when serialized. Create Model:
Use mongoose.model() to create the Post model from the schema. Export Model:
Export the Post model for use in other parts of the application.