mongoose 连接到数据库时,`useFindAndModifiaed`不是有效的操作

f1tvaqid  于 12个月前  发布在  Go
关注(0)|答案(2)|浏览(119)

我目前正在学习后端,也不熟悉它
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);

字符串

jexiocij

jexiocij1#

有两种方法可以解决这个问题,将useFindAndModify放在mongoose.connect选项对象中,并将extender更改为extended

app.use(express.json({ limit: "30mb", extended: true }));
app.use(express.urlencoded({ limit: "30mb", extended: true }));

字符串
或将mongoose降级到版本5,因为useFindAndModify已被弃用https://mongoosejs.com/docs/deprecations.html#findandmodify

sigwle7e

sigwle7e2#

useFindAndModify选项在版本5.10.0中被弃用,在版本6.0.0中被删除。
您可以通过将mongoose版本降级到5.10.13来解决此问题

相关问题