const mongoose = require("mongoose");
mongoose.set('strictQuery', false);
mongoose.connect("mongodb://localhost:27017/fruitsDB", {useNewUrlParser: true});
const fruitSchema = new mongoose.Schema ({
name:String,
rating: Number,
review: String
});
const Fruit = mongoose.model("Fruit", fruitSchema);
const fruit = new Fruit ({
name: "Apple",
rating: 7,
review: "Pretty good"
});
fruit.save();
This is my code.
$ node app.js
C:UsersAmanDesktopfruitsProjnode_modulesmongooselibdriversnode-mongodb-nativecollection.js:175
const err = new MongooseError(message);
^
MongooseError: Operation `fruits.insertOne()` buffering timed out after 10000ms
at Timeout.<anonymous> (C:UsersAmanDesktopfruitsProjnode_modulesmongooselibdriversnode-mongodb-nativecollection.js:175:23)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7)
Node.js v18.14.0
This is the error
I am following an online course and currently facing an error.
Please help me out with this.
2
Answers
Hope this code will work for you.
And also you may have did one error in insertOne() function, that’s why its throwing an error in the console.
You must use the this format while using insertOne() function:-
(As per your code, here "modelName" is "Fruit")
Upvote if this answer looks useful to you 🙂