mongoose.connect
部分给我带来了问题。如果我不包含useNewUrlParser:true,使用UnifiedTopology:true,在终端中运行app.js会给予我关于包含这些部分的DeprecationWarning。但是,如果我添加了它们,运行app.js什么也不做。它永远冻结了。
//jshint esversion:6
const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost:27017/", {
useNewUrlParser: true, useUnifiedTopology: true
});
//Schema is scaffolding of date. For instance here's one for fruits.
const fruitSchema = new mongoose.Schema({
name: String,
rating: Number,
review: String
});
//This part is also required for upper one to work.
const Fruit = mongoose.model("Fruit", fruitSchema);
const fruit = new Fruit({
name: "Apple",
rating: 7,
review: "I loved it."
});
fruit.save();
1条答案
按热度按时间yx2lnoni1#