Posts

Showing posts from July, 2025

taking multiple inputs as a field (Schema)

 tags:[String]

assigning updatedAt field

 updatedAt:{ type:Date, default:Date.now } ___Schema.pre("save", function(next){ this.updatedAt: Date.now(); next(); });

giving mongoDB userId as official userId for user schema

 userId:{ type:mongoose.Schema.Types.ObjectId, ref:"User", required:true }

assigning value between two options in a mongoDB Schema

 we use enum to allocate value between two options  status: { type: String, enum: ["draft", "published"], default: "draft" }