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

370
Views
Mongoose obtiene todos los documentos donde la fecha y el número de semanas tienen la fecha actual

Tengo este tipo de documentos en mongoDB.

 { _id:620df4541571891a71dfa372 user_id:61cc109f967b757d484fbf3b instrument_type:"binance" sub_instrument:"BTC/USDT" start_date:2022-02-17T00:00:00.000+00:00 type_quantity:2 prediction:"High" points:12 price:null run_at:null createdAt:2022-02-17T07:08:04.633+00:00 updatedAt:2022-02-17T07:08:04.633+00:00 }

Aquí tengo "start_date", que es el día de inicio. "type_quantity", que es el número de semanas desde el día de inicio.

Ejemplo: si "start_date" es 2022-02-17T00:00:00.000+00:00 y "type_quantity" es 2. Entonces, las fechas por semana serán 2022-02-17, 2022-02-24 y 2022-03 -03. Y si la fecha actual es una de estas fechas, obtenga este documento.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede usar $dateAdd en una consulta de agregación como esta:

Tenga en cuenta que aquí solo es necesaria una etapa $match con $expr para obtener documentos donde:

  • La fecha actual ( $$NOW ) es mayor o igual que $start_date .
  • La fecha actual ( $$NOW ) es menor o igual que la fecha calculada sumando X semanas.

es decir, la fecha encontrada está entre $start_date y start_date + X semanas.

 db.collection.aggregate([ { "$match": { "$expr": { "$and": [ { "$gte": [ "$$NOW", "$start_date" ] }, { "$lte": [ "$$NOW", { "$dateAdd": { "startDate": "$start_date", "unit": "week", "amount": "$type_quantity" } } ] } ] } } } ])

Ejemplo aquí agregando más documentos.

over 4 years ago · Santiago Trujillo Report
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!