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

207
Vistas
Count of a nested value of all entries in mongodb collection

I have a collection named outbox which has this kind of structure

"_id" :ObjectId("5a94e02bb0445b1cc742d795"),
"track" : {
    "added" : {
        "date" : ISODate("2020-12-03T08:48:51.000Z")
    }
},
"provider_status" : {
    "job_number" : "",
    "count" : {
        "total" : 1,
        "sent" : 0,
        "delivered" : 0,
        "failed" : 0
    },
    "delivery" : []
}

I have 2 tasks. First I want the sum of all the "total","sent","failed" on all the entries in the collection no matter what their objectId is. ie I want sum of all the "total","sent","delivered" and "failed". Second I want all these only for a given object Id between Start and End date. I am trying to find total using this query

db.outbox.aggregate(
{ $group: { _id : null, sum : { $sum: "$provider_status.count.total" } } });

But I am getting this error as shown Error Image

Since I do not have much experience in mongodb I don't have any idea how to do these two tasks. Need help here.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You are executing this in Robo3t seems like.

You need to enclose this in an array like

db.test.aggregate([ //See here
  {
    $group: {
      _id: null,
      sum: {
        $sum: "$provider_status.count.total"
      }
    }
  }
])//See here

But it's not the case with playground as they handle them before submitting to the server

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