unending Sending request with Get ... Issue when trying to 'get' data from the mongoDB through Postman/ Thunder Client eeventhough there is no error

Viewed 143

I have a mongodb collection with a few examples and I was trying to display them on my get method but it keeps showcasing the Processing, Please wait... buffer screen without outputting any result. I am wondering why it takes so long and does not display even after an hour and more when it displayed quite quickly on my simpler tests before.

This is my Usermodel

const mongoose = require("mongoose")

const userSchema = new mongoose.Schema(
    {
        username: { type:String,unique:true,required:true},
        email:{type:String,unique:true,required: true},
        password:{type: String,required:true,},
        isAdmin:{type:Boolean,default: false,}, },
    {
        timestamps: true,
    });
const userModel = mongoose.model("users_list",userSchema); 

This is the user router

const express = require('express');
const userModel = require('../models/users');
const { model } = require('mongoose');
const router = require("express").Router();

router.get("/getUser",(req,res)=> {
    userModel.find({},(err,result)=>{
        if(err){
            res.json("There is an error");
        }
        else{
            res.json(result);
            console.log("got result");
            console.log(result);
        }
    });
    res.send("Ok");
});
module.exports = router;

And here is how my index.js where all the routers are called and fixated.

const express = require('express');
const app = express()
const mongoose = require('mongoose'); 
const dotenv = require('dotenv');
const userRouter = require('./apis/routers/userRouter');
const cors = require("cors");
dotenv.config();

mongoose
.connect(process.env.MONG_URL)
.then(() => console.log("DB Connection Successful!"))
  .catch((err) => {
    console.log(err);
  });

app.use(cors);
app.use(express.json());
app.use('/api/users',userRouter);

I have given the right MongoDB URL and it is not enclosed in quotation marks or anything from .env

And right here as you can see in the image, the postman keeps doing this This sending request is unending and doesn't fetch the data at all. How can I resolve this? Unending sending request

0 Answers
Related