{"size": 597, "ext": "js", "max_stars_repo_path": "models/blog.js", "max_stars_repo_name": "amirshaikh2699/blogs-be", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "models/blog.js", "max_issues_repo_name": "amirshaikh2699/blogs-be", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "models/blog.js", "max_forks_repo_name": "amirshaikh2699/blogs-be", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.5862068966, "max_line_length": 46, "alphanum_fraction": 0.6013400335}
const mongoose = require("mongoose");

const blog = new mongoose.Schema({
  title: { type: String, required: true },
  content: { type: String, required: true },
  name: { type: String, required: true },
  blogimage: { type: String },
  country: { type: String, required: true },
  updatedAt: {
    type: Date,
    default: Date.now,
  },
  createdAt: {
    type: Date,
    default: Date.now,
  },
});

blog.pre("save", (next) => {
  let now = new Date();
  this.updatedAt = now;
  if (!this.createdAt) {
    this.createdAt = now;
  }
  next();
});

module.exports = mongoose.model("Blog", blog);
