timestamp mongoose code example

Example 1: mongoose timestamps

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

Example 2: 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;

Example 3: schema mongoose

const fruitSchema = new mongoose.Schema ({
  name: {
    type: String
  },
  rating: {
    type: Number,
    min: 1,
    max: 10
  },
  review: String
});

Example 4: timestamps in mongoose

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