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

453
Views
Cómo realizar el adelanto y el retraso en MongoDB

Estoy usando STudio 3T y tengo una consulta como esta:

 select [Dashbo],lead([Dashbo]) over(order by [Entered Date]) from ATest_prevback;

Esto me está dando un error. ¿Cómo realizar esto en MongoDB? ¿Puede alguien darme un ejemplo?

Gracias, adi

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Desafortunadamente, no es posible.

Solución alternativa: cree una vista materializada con datos calculados.

Ejecutar en MongoDB Shell:


 var prev = null; db.ATest_prevback.find({}).sort({field:1}).forEach(function(curr){ db.materialized_view.insert({curr:curr.field, prev:(prev ? prev.field : 0)}) prev = curr; })

Ejecute consultas de lead y lag "falsas":

 db.materialized_view.aggregate([ {$match:{$expr:{$eq:["$curr", "$prev"]}}} ])
over 4 years ago · Santiago Trujillo Report

0

A partir de MongoDB v5.0+, se puede hacer usando $shift en $setWindowFields .

 db.collection.aggregate([ { "$setWindowFields": { "partitionBy": null, "sortBy": { "entered_date": 1 }, "output": { lag: { $shift: { output: "$Dashbo", by: -1, default: "Not available" } }, lead: { $shift: { output: "$Dashbo", by: 1, default: "Not available" } } } } } ])

Aquí está el parque infantil de Mongo para su referencia.

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!