Abed NooRi
Abed NooRi

Reputation: 1

article.createdAt.toLocalDateString is not a function

var mongoose = require("mongoose");

var articleSchema = new mongoose.Schema({
    Title : String,
    Image : String,
    Description : String,
    createdAt : {
        type : Date,
        default : new Date()
    }
});

var article = mongoose.model("Articles", articleSchema);

module.exports = article;

Upvotes: 0

Views: 81

Answers (1)

NinaW
NinaW

Reputation: 658

const mongoose = require("mongoose");

const articleSchema = mongoose.Schema({
  title: { type: String },
  image: { type: String },
  description: { type: String },
  createdAt: { type: Date, default: Date.now }
});

const article = mongoose.model("Articles", articleSchema);

module.exports = article;

https://mongoosejs.com/docs/2.7.x/docs/defaults.html

Upvotes: 1

Related Questions