Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda