MongoDB and Mongoose - Create and Save a Record of a Model

i am getting error on this topic
MongooseError: Operation people.insertOne() buffering timed out after 10000ms
PLEASE FIX THIS

WHEN I OPEN MongoDB THEN I WILL CONNECT FROM Connecting with the MongoDB Driver
In the MongoDB version, I have the latest 5.5 or later selected I have set this URL in .env
mongodb+srv://:@cluster0.bqy3vdg.mongodb.net/?retryWrites=true&w=majority
I have added a username and password and I am using this code

var createAndSavePerson = (done) => {
  let person = new Person({
    name: "bhavik",
    age: 30,
    favoriteFoods: ['IT'],
  });

  person.save(function(err, data) {
    if (err) {
      console.log(err);
    } else {
      done(null, data);
    }
  });
};

but it gives me error when I add the URL http://localhost:3000/ in Solution Link then it gives me an error
// running tests Creating and saving a db item should succeed (Test timed out) // tests completed

Failed:Creating and saving a db item should succeed
and the terminal showing this error 
MongooseError: Operation `people.insertOne()` buffering timed out after 10000ms
    at Timeout.<anonymous> (C:\Users\HOME\OneDrive\Desktop\boilerplate-mongomongoose-main\boilerplate-mongomongoose-main\node_modules\mongoose\lib\drivers\node-mongodb-native\collection.js:198:23)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)
how can I fix this

Post a GitHub repo with your code or put it on Replit. We need to see all the code and we need to be able to test it.


There is nothing wrong with the code you posted or with the tests and it works just fine for me locally. So it is definitely something on your end with the DB connection. I might suggest you try it on Replit instead as well.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.