我目前正在学习后端,也不熟悉它
gritting this error calls 'usefindandmodify' is invalid operation这是什么错误?
x1c 0d1x的数据
它还说如果(VALID_OPTIONS.indexOf(key)= -1)抛出新错误(\
${key}是无效的选项。
); ^
import mongoose from "mongoose";
import cors from "cors";
const app = express();
app.use(express.json({ limit: "30mb", extender: true }));
app.use(express.urlencoded({ limit: "30mb", extender: true }));
app.use(cors());
const CONNECTION_URL =
"priyanshu74:****@cluster0.2l3k1.mongodb.net/myFirstDatabase?retryWrites=true&w=majorityconst PORT = process.env.PORT || 5000"
mongoose
.connect(CONNECTION_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() =>
app.listen(PORT, () => console.log(`server running on port: ${PORT}`))
)
.catch((error) => console.log(error.message));
mongoose.set("useFindAndModify", false);
字符串
2条答案
按热度按时间jexiocij1#
有两种方法可以解决这个问题,将
useFindAndModify
放在mongoose.connect
选项对象中,并将extender
更改为extended
字符串
或将mongoose降级到版本5,因为
useFindAndModify
已被弃用https://mongoosejs.com/docs/deprecations.html#findandmodifysigwle7e2#
useFindAndModify
选项在版本5.10.0中被弃用,在版本6.0.0中被删除。您可以通过将mongoose版本降级到5.10.13来解决此问题