mongoose created at code example

Example 1: mongodb created_at updated_at

var thingSchema = new Schema({..}, { 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: mongodb created_at updated_at

var thingSchema = new Schema({..}, { timestamps: { createdAt: 'created_at' } });

Example 4: schema mongoose

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

Tags:

Misc Example