I want to add documents to mongoose model in database automatically daily,So that when ever new day begins a new record entry is added in database. Following are my model and schemas:
import { Schema, model, ObjectId } from "mongoose";
export type salahStatus = {
fajr: boolean;
dhuhr: boolean;
asr: boolean;
maghrib: boolean;
isha: boolean;
};
export type salahRecordT = {
date: Date;
} & salahStatus;
//Schema for recording Salahs of each day
const SalahRecordSchema = new Schema<salahRecordT>({
date: {
type: Date,
required: true,
},
fajr: {
type: Boolean,
default: false,
},
dhuhr: {
type: Boolean,
default: false,
},
asr: {
type: Boolean,
default: false,
},
maghrib: {
type: Boolean,
default: false,
},
isha: {
type: Boolean,
default: false,
},
});
export interface UserT {
_id: ObjectId;
isVerified: boolean;
name: string;
email: string;
password: string;
salahRecord: salahRecordT[];-->need to add entry here daily
googleToken: string;
}
//Main User Schema for recording user data
const UserSchema = new Schema<UserT>({
isVerified: {
type: Boolean,
},
name: {
type: String,
required: true,
},
email: {
type: String,
required: true,
},
password: {
type: String,
},
salahRecord: [SalahRecordSchema],
googleToken: {
type: String,
},
});
const User = model<UserT>("users", UserSchema);
export default User;
I want that when ever new days begins. new document is added in db which is of salah record schema .For example following entry should be added each day
{
date: Date,
fajr: false
dhuhr: false,
asr: false,
maghrib: false,
isha: false
}
How can i achieve this in mongoose??