我只是从我的数据库创建一个名为 Fruits 的数据库app.js
,并使用 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();
Run Code Online (Sandbox Code Playgroud)
每当我尝试时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);` …
Run Code Online (Sandbox Code Playgroud)