Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
How to add documents in mongoose automatically based on date

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??

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!