Skip to content

Instantly share code, notes, and snippets.

@sankalpdeveloper
Last active June 26, 2022 13:31
Show Gist options
  • Select an option

  • Save sankalpdeveloper/cd0e63c93c89593e75403eca4d9f4d05 to your computer and use it in GitHub Desktop.

Select an option

Save sankalpdeveloper/cd0e63c93c89593e75403eca4d9f4d05 to your computer and use it in GitHub Desktop.
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
var aggregatePaginate = require("mongoose-aggregate-paginate-v2");
const feedbackSchema = Schema({
user_id: { type: Schema.Types.ObjectId, ref: 'user' },
profile_id: { type: Schema.Types.ObjectId, ref: 'profile' },
feedback: {
type: String,
required: true,
},
is_read: {
type: Boolean,
default: 0,
},
is_deleted: {
type: Boolean,
default: 0,
},
}, {timestamps: true });
feedbackSchema.plugin(aggregatePaginate);
module.exports = feedback = mongoose.model("feedback", feedbackSchema);

{timestamps: true }

If we add this to mongose schema it create CreatedAt & UpdatedAt feild on document create and update Updated At update , updateMany findandudateOne

Referance Link https://mongoosejs.com/docs/timestamps.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment