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();
CodePudding user response:
Create model name as "person" since people is plural already and it may cause error And make sure you run mongod server in the background using git
CodePudding user response:
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