Подключен ли mon goose к версии, указанной в c? - PullRequest
0 голосов
/ 27 мая 2020

mon goose .connect <- эта часть вызывает у меня проблемы. Если я не включаю useNewUrlParser: true, useUnifiedTopology: true, запуск приложения. js в терминале даст мне DeprecationWarning о включении этих частей. Однако, если я их добавлю, запуск app. js ничего не сделает. Просто замирает навсегда. </p>

//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 Ответ

1 голос
/ 31 мая 2020
mongoose.connect("mongodb://localhost:27017/fruitsDB", {
useUnifiedTopology: true,
useNewUrlParser: true
})
.then(() => console.log('DB Connected!'))
.catch(err => {
console.log("DB Connection Error: ${err.message}");
});
...