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

192
Vistas
Cannot read properties of undefined (reading 'populate')

here i am taking ref from category and sub category field from their database and want to populate the name of category and sub category but getting this error "Cannot read properties of undefined (reading 'populate')"

    this.products.findOne({ _id: req.query.productId }, { createdAt: 0, updatedAt: 0, isActive: 0, isDeleted: 0, __v: 0 })
        .exec(function (error, data) {
            if (error) {
                callback(error);
            }
            if (data && data.length == 0) {
                return callback(false, common.errorMsg("NO Details FOUND"));
            } else {
                // return callback(false, common.successMsg("product list", data));
                data=data.map(function(item){
                    return {
                        productId: item._id,
                    productName: item.productName,
                    storeName: item.createdBy.fullName,
                    categoryName:item.category.name,
                    subCategoryName:item.subCategory.name,
                    image: item.fabricType[0].style[0].images[0],
                    price: item.price
                    }
                })
            }
            return callback(false, common.successMsg("product", data));
        }).populate('createdBy').populate('category').populate('subCategory').lean()
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The exec method returns a promise, so after that, you can't call the populate function. try this code:

this.products
   .findOne(
       { _id: req.query.productId },
       { createdAt: 0, updatedAt: 0, isActive: 0, isDeleted: 0, __v: 0 },
   )
   .populate('createdBy')
   .populate('category')
   .populate('subCategory')
   .lean()
   .exec(function (error, data) {
       // ...
   })
about 4 years ago · Juan Pablo Isaza 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