Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

120
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda