我正在从我的 app.js
中创建一个名为 Fruits 的数据库,并使用 Mongoose 将数据库连接到 MongoDB。
const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost:27017/fruitsDB", {useNewUrlParser: true});
mongoose.set('strictQuery', false);
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: "Taste Good"
});
fruit.save();
每当我尝试运行
node app.js
时,都会收到DeprecationWarning的警告。即使我尝试使用mongoose.set('strictQuery', true);
,但仍然会出现以下相同的错误:(node:15848) [MONGOOSE] DeprecationWarning: Mongoose: the `strictQuery` option w
ill be switched back to `false` by default in Mongoose 7. Use `mongoose.set('str
ictQuery', false);` if you want to prepare for this change. Or use `mongoose.set
('strictQuery', true);` to suppress this warning.
(Use `node --trace-deprecation ...` to show where the warning was created)
D:\Web Development\FruitsProject\node_modules\mongoose\lib\drivers\node-mongodb-
native\collection.js:158
const err = new MongooseError(message);
^
MongooseError: Operation `fruits.insertOne()` buffering timed out after 10000ms
at Timeout.<anonymous> (D:\Web Development\FruitsProject\node_modules\mongoo
se\lib\drivers\node-mongodb-native\collection.js:158:23)
at listOnTimeout (node:internal/timers:564:17)
at process.processTimers (node:internal/timers:507:7)
Node.js v18.12.1
接着第二个错误也出现在fruits.insertOne()。
因此,我的MongoDB数据库没有被更新。
test> show dbs
admin 40.00 KiB
config 108.00 KiB
local 40.00 KiB
shopDB 72.00 KiB
我只想修复这个错误。但我不知道在哪里修复这个错误。对于错误的第二部分,似乎是来自于node_modules本身。我该如何修复这个错误?
node_modules
" 的文件夹)? - Peter Mortensen