article.createdAt.toLocalDateString не является функцией - PullRequest
0 голосов
/ 21 марта 2020
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;

1 Ответ

1 голос
/ 21 марта 2020
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

...