Why i am getting error .map function is not defined (data.map)

 async productDetails(language, req, callback) {

        this.products.findOne({ _id: req.query.productId }, { createdAt: 0, updatedAt: 0, isActive: 0, isDeleted: 0, __v: 0 })
                .populate('createBy')
                .populate('category')
                .populate('subCategory')
               
                .exec(function(error,data){
                        console.log("777777777777777777",data)
                    if (error) {
                        callback(error);
                    }
                    if (data && data.length == 0) {
                        return callback(false, common.errorMsg("NO Details FOUND"));
                
                    }
                    
                     else {
                        
                        data=data.map(function(details){
    
                               return {
                                storename : details.createdBy.fullName,
                                categoryname :details.category.name,
                                subcategoryname :details.subCategory.name
                               }
    
                        })
                        return callback(false, common.successMsg("product list", data));
                    }
                })
        }

reply a link to the challenge pls.
It is easier to jump to the correct step, if you do so.

thats fine now ive fixed this already by taking data into an array

1 Like