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

139
Views
I'm using an aggregate function from mongodb, the problem is that I need only one information in my console

In my case I only want get a number to use it. This is my schema:

const personaSchema = mongoose.Schema({
    nombre:String,
    direccion: String,
    dineroRecibido: Number,
    fecha: String
},{versionKey: false})

this is my aggregate function:

const mostrarSumaDinerosPorDia = async (fecha) =>{
    const sumaDineroHoy = await PersonaModel.aggregate(
      [
          {$match:{fecha:fecha}},
          {$group:{_id:'$fecha'   ,total:{$sum:'$dineroRecibido'}}}
      ]  
    
    )
   
    console.log(sumaDineroHoy)
}

and this is my answer console:

[ { _id: '24 de diciembre del 2021', total: 10000 } ]

I only want get 10000, no more.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Add this to your aggregation pipeline { $project: { "_id": 0 } }

More info on $project here: $project MongoDB

about 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!