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

821
Views
Agregación de Golang mongodb usando mongo-driver

Estoy tratando de realizar la siguiente consulta de Mongo en Golang usando mongo-driver:

 var currentDate = ISODate("2021-01-22T00:00:00Z") var someValue = "A" db.someCollection.aggregate([ {$match: {"data.date": currentDate, someAttribute: someValue}}, {$project: { data: {$filter: { input: '$data', as: 'df', cond: {$eq: ['$$df.date', currentDate]} }}, _id: 0 }} ])

He intentado lo siguiente sin mucha suerte:

 currentDate := time.Date(2021, 1, 22, 0, 0, 0, 0, time.UTC) someValue := "A" matchStage := bson.D{{"$match", bson.D{{"data.date", currentDate}, {"someAttribute", someValue}}}} projectStage := bson.D{{"$project", bson.D{{"data", bson.D{{"$filter", bson.D{{"input", "'$data'"}, {"as", "df"}, {"cond", bson.D{{"eq", bson.A{"$$df.date", currentDate}}}}}}}}}}} cur, err := someCollection.Aggregate(a.ctx, mongo.Pipeline{matchStage, projectStage})

Obteniendo el siguiente error: input to $filter must be an array not string

¿Cómo puedo solucionar esto?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Respondiendo a mi propia pregunta, podría ser útil para cualquiera que enfrente este problema más adelante.

Aquí esta lo que hice:

 currentDate := time.Date(2021, 1, 22, 0, 0, 0, 0, time.UTC) someValue := "A" matchStage := bson.D{{"$match", bson.D{{"data.date", currentDate}, {"someAttribute", someValue}}}} projectStage := bson.D{ {"$project", bson.D{ {"_id", 0}, {"data", bson.D{ {"$filter", bson.D{ {"input", "$data"}, {"as", "df"}, {"cond", bson.D{ {"$eq", bson.A{"$$df.date", currentDate}}, }}, }}, }, }}, }, }

Agregué el _id y eliminé la comilla simple alrededor de $data

Salud

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!