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

188
Views
TypeError: _models_Products__WEBPACK_IMPORTED_MODULE_1__.default.find is not a function

I am making Next Js web application and browesr is showing type error in 7th line in first block of code .The error is under Product.find()
TypeError: models_Products__WEBPACK_IMPORTED_MODULE_1_.default.find is not a function

   6 | const handler = async (req, res) => {
>  7 |   let products = await Product.find();
     |                       ^
   8 |  
   9 |   res.status(200).json({ products });
  10 | };

**This is my database of mongodb **



import mongoose from "mongoose";

const connectDb = (handler) => async (req, res) => {
  if (mongoose.connections[0].readyState) {
    return handler(req, res);
  }
  await mongoose.connect(process.env.MONGO_URI);
  return handler(req, res);
};
export default connectDb;

`

This is connection of my database to next js app in api folder



import connectDb from "../../database";
import Product from "../../models/Products";

const handler = async (req, res) => {
  let products = await Product.find();

  res.status(200).json({ products });
};

export default connectDb(handler);

*This is my product schema



const mongoose=require("mongoose")

const productSchema=new mongoose.Schema({

    title:{
        type:String,
        required:true
    },
    slug:{
        type:String, required:true
    },
    desc:{type:String,required:true},
    img:{type:String,reuired:true},
    category:{type:String,reuired:true},
    size:{type:String},
    color:{type:String},
    price:{type:Number},
    availableQty:{type:String,required:true}
   

},{timestamps:true});

mongoose.models={}

export default mongoose.model=('Product',productSchema)
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Try to export your model like this:

export default mongoose.models?.Product || mongoose.model('Product', productSchema);

You may remove the mongoose.models = {} line.

about 4 years ago · Santiago Gelvez 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!