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

175
Vistas
The mongoose find() method is not a function error in the service call

When I tried to implement an express get service call with a mongoose find method it is giving me 'Product.find' is not a function error.

FYI-'Product' is the mongoose model which I imported .

ROUTES FILE

const express = require('express');
const routes = express.Router();
const Product = require('../models/product');

routes.get('/',(req,res)=>{
const list= Product.find();
res.send(list);
})

MODEL FILE

const mongoose = require('mongoose');
const productSchema = mongoose.Schema({
name:String,
subject:String
})
exports.Product = mongoose.model('Product',productSchema);

ERROR

TypeError:Product.find is not a function.
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

When you are exporting the model like exports.Product,you need to import the model in routes file as an object.

const {Product} = require('../models/product');

OR

we can use module.exports instead of exports.Product without making any changes in the import of routes file.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Because you are not importing your model in route file. Better if you can use module.exports instead of exports.Product.

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