Infinite requests to MongoDB while working with mongoose (Next.js)


I am trying to connect to my MongoDB database. While doing that I get the infinite request to my DB. I do not know why it happens, but it does not effect to my project directly, but it loads the traffic. I do not know how to stop it. I am using mongoose library for this purpose and I am working on Next.js.

import mongoose from "mongoose"

const connect = async () => {
    try {
        await mongoose.connect(process.env.MONGODB_URI)
        console.log("MongoDB Connected");
    } catch (error) {

export default connect;

That is my code, pretty simple. Do you know what can cause such a problem?

Hi @Ako_M, welcome to the community!!

The code that you shared with us looks good. And your problem may not be on this part of your code.

Based on the second image that you shared. Your problem is your frontend page doing a lot of requests on your server. So, it hasn’t directly relation with MongoDB. As you mention that are using Nextjs, I recommend you try to search for help with your Nextjs code to avoid a lot of requests to GET users.

1 Like

@Jennysson_Junior Thank you very much for your respond. My issue really was on frontend side, and I could fix it. Thanks a lot!