Answers for "timestamps true mongoose"

1

timestamps true mongoose

const userSchema = mongoose.Schema(
  {
    email: String,
  },
  { timestamps: true }
);

const User = mongoose.model("User", userSchema);

const doc = await User.create({ email: "[email protected]" });

doc.createdAt; // 2020-07-06T20:36:59.414Z
doc.updatedAt; // 2020-07-06T20:36:59.414Z

doc.createdAt instanceof Date; // true
Posted by: Guest on February-26-2021
4

mongoose schema

const mongoose = require('mongoose');

const UserSchema = new mongoose.Schema({
    name: {
        type: String,
        required: true
    }
}, {
    timestamps: true
})

const User = mongoose.model('User', UserSchema);

module.exports = User;
Posted by: Guest on October-03-2020
3

mongoose schema

var mongoose = require('mongoose');
  var Schema = mongoose.Schema;

  var blogSchema = new Schema({
    title:  String, // String is shorthand for {type: String}
    author: String,
    body:   String,
    comments: [{ body: String, date: Date }],
    date: { type: Date, default: Date.now },
    hidden: Boolean,
    meta: {
      votes: Number,
      favs:  Number
    }
  });
Posted by: Guest on June-15-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language