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

357
Views
mangosta UnCaught TypeError: foundProduct.greet no es una función

Así que el título lo dice todo. Parece que por alguna razón no puedo acceder a la función de saludo y realmente no entiendo por qué. Estoy siguiendo a un maestro de un curso y todo parece estar funcionando bien en su lado, este es el .js:

 const mongoose = require("mongoose"); mongoose.connect("mongodb://localhost:27017/shopApp") .then(() => { //check if you succesfully connect to mongodb console.log("Connection Open !") }) .catch(err => { console.log("Oh No Error") console.log(err) }) const productSchema = new mongoose.Schema({ name: { type: String, required: true, maxLength: 20 }, price: { type: Number, required: true, min: [0, "Price must be positive !"] }, onSale: { type: Boolean, default: false }, categories: [String], qty: { online: { type: Number, default: 0 }, inStore: { type: Number, default: 0 } }, size: { type: String, enum: ["S", "M", "L"]//these are the only string that'll be accepted } }) const Product = mongoose.model("Product", productSchema) productSchema.methods.greet = function () { console.log("hello ! ") console.log(`- from ${this.name}`) } const findProduct = async () => { const foundProduct = await Product.findOne({ name: "Tire pump" }); foundProduct.greet(); } findProduct()

Sé que el problema es de const Product y de abajo, pero no puedo encontrar nada malo

y aquí está la respuesta que obtengo cuando cargo product.js con el nodo:

TypeError no capturado: foundProduct.greet no es una función

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!