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

141
Views
Agregar conteo dentro de la agregación de MongoDB

Cómo agregar conteo dentro de la agregación de MongoDB. En esta agregación, estoy ordenando los datos por "categoría" de campo anidado profundo. Producto de catálogo es un ObjectId de producto de catálogo. Dentro del producto del catálogo tengo un ObjectId de categoría.

 products = await StorageModel.aggregate([ { $lookup: { // Replace the Catelog Product ID with the Catelog Product from: "catalogs", localField: "catalogProduct", foreignField: "_id", as: "catalogs" } }, { $lookup: { // Replace the Category ID with the Category from: "categories", localField: "catalogs.category", foreignField: "_id", as: "catalogs.category" } }, { $addFields: { // Replace the Category with its name "catalogs.category": "$catalogs.category" } }, { $match: { "catalogs.category._id": { $in: ids } } }, { $lookup: { // Replace the Catelog Product ID with the Catelog Product from: "catalogs", localField: "catalogProduct", foreignField: "_id", as: "catalogProductNew" } }, { $count: "count" }, { $sort: { _id: -1 } }, { $skip: (page - 1) * 8 }, { $limit: 8 }, ]);

Devoluciones. Pero otro dato de la agregación fue borrado.

 [ { count: 3 } ]

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