我是MERN技术栈的初学者,正在跟随YouTube上的教程学习。我在使用Mongoose时遇到了一个错误。
Error: `useFindAndModify` is an invalid option
我找不到任何解决方案。
import express from "express";
import bodyParser from "body-parser";
import mongoose from "mongoose";
import cors from "cors";
const app = express();
app.use(bedyParser.json({ limit: "30mb", extended: true }));
app.use(bodyParser.urlencoded({ limit: "30mb", extended: true }));
app.use(cors());
const CONNECTION_URL =
"mongodb+srv://myratcharyyev:<password>@clustero.mn9xi.mongodb.net/myFirstDatabase?retryWrites=true&w=majority";
const PORT = process.env.PORT || 5000;
mongoose
.connect(CONNECTION_URL, {
useNewUrlParser: true,
useUnifiedTopology: true
// useCreateIndex: true
})
.then(( =>
app.listen (PORT, () => console.log("Server running on port: ${PORT}'))
)
.catch((error) => console.log(error message));
mongoose.set("useFindAndModify", false);