mongoose.connect是一个特定的版本吗?

问题描述 投票:0回答:1

mongoose.connect <-这部分给我带来了问题。如果我不包含useNewUrlParser: true, useUnifiedTopology: 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();
mongoose connect freeze deprecation-warning
1个回答
1
投票
mongoose.connect("mongodb://localhost:27017/fruitsDB", {
useUnifiedTopology: true,
useNewUrlParser: true
})
.then(() => console.log('DB Connected!'))
.catch(err => {
console.log("DB Connection Error: ${err.message}");
});
© www.soinside.com 2019 - 2024. All rights reserved.