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

79
Views
Búsqueda y relajación de MongoDB

Estoy tratando de realizar una búsqueda que funciona bien y en el documento correcto como 'métricas'. El documento de búsqueda tiene una matriz dentro de su objeto llamada 'historial'. Estoy tratando de deshacer ese historial y realizar una faceta en él, una consulta de agregación que tengo directamente en la colección de búsqueda que funciona bien.

Sin embargo, cuando lo usa aquí, no devuelve nada. ¿Estoy desenrollando esto incorrectamente? ¿Debería ser $metrics.history ?

 { from: 'historicprices', localField: 'collectibleId', foreignField: 'collectibleId', pipeline: [ {$set: {"target-date": "$$NOW"}}, {$unwind: {path: "$history"}}, {$facet: { "one_day": [ { $match: { $expr: { $lte: [{$subtract: ["$target-date", "$history.date" ]}, {$multiply: [24,60,60,1000] }] } } }, { $group: { _id: null, "first": { $first: "$history.value" }, "last": { $last: "$history.value" }, "min-price": {"$min": "$history.value"}, "max-price": {"$max": "$history.value"} } }, { $unset: ["_id"]} ] "one_week": [ { $match: { $expr: { $lte: [{$subtract: ["$target-date", "$history.date" ]}, {$multiply: [7, 24, 60, 60, 1000] }] } } }, { $group: { _id: null, "min-price": {"$min": "$history.value"}, "first": { $first: "$history.value" }, "last": { $last: "$history.value" }, "max-price": {"$max": "$history.value"} } }, { $unset: ["_id"]} ] }} ], as: 'metrics', }

Gracias

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tal vez necesite agregar preserveNullAndEmptyArrays: true a su etapa de relajación. De lo contrario, no se recibirán datos si uno de los documentos no devuelve este campo.

about 4 years ago · Juan Pablo Isaza 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!