skip to Main Content

Using the MongoDb and Mongoose for the first time to store the data of my app.js file. When I run the app.js then it throws this error after a while -> MongooseError: Operation peoples.insertOne() buffering timed out after 10000ms.

import mongoose from "mongoose";

mongoose.set("strictQuery", false);
mongoose.connect(
  "mongodb://localhost:27017/peopleDB",
  { useNewUrlParser: true },
  (err) => {
    if (err) console.log(err);
    else console.log("MongoDB is connected");
  }
);

const peopleSchema = new mongoose.Schema({
  name: String,
  age: Number,
});

const People = new mongoose.model("People", peopleSchema);

const people = new People({ name: "John", age: 37 });

people.save();

this is the code that I wrote

2

Answers


  1. Chosen as BEST ANSWER

    After a lot of searching for the solution got to know that the connection was not made, if you are using the node the latest node.js version then replace the "localhost" with "127.0.0.1" and then try running the app.js


  2. Create model name as "person", since people is already plural, and it may cause an error.
    And make sure you run mongod server in the background using git

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search