error : .find(…) is not a function nodejs mongoose

  api, get, javascript, mongoose, node.js

I define a controller which code like bellow :

const  paymentModel = require("../../models/University");
class PaymentController {
async getPaymentList(req , res){
   const list = await paymentModel.find() 
   .select("amount  description  payDate payId" ).limit(20);
   res.send(list);
}

router like bellow :

const router = require ("express").Router();
const controller = require("../http/controller/PaymentController");
router.get('/' ,controller.getPaymentList);
module.exports= router;

model :

 const mongoose = require ("mongoose");
 const schemaPay = new mongoose.Schema({
 payId  :{type:Number, required: true},
 amount :{type :String , required: true},
 description :{type :String , required:true},
 courseId:[schemaCourse] ,
 studentId:[schemaStudent],
 payDate :String ,
 });

 module.exports={paymentModel };

when I test api with postman I get error :paymentModel.find is not a function
can any one help me where is the problem?

Source: Ask Javascript Questions

LEAVE A COMMENT