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

176
Views
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 answers
Answer question

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 Report

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 Report
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!