简体   繁体   中英

Mongoose giving error not connetig to server

Connection code

const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost:27017/test");

const Cat = mongoose.model("Cat", { name: String });

const kitty = new Cat({ name: "Zildjian" });
kitty.save().then(() => console.log("meow"));

I have defined path variable for MongoDB in Environment variables and it's working, I have checked it by running mongod in cmd and it's not giving error. 控制台中的错误

这是我的PowerShell屏幕截图

changing the connection url make my code run successfully..

mongoose.connect("mongodb://127.0.0.1:27017/test");

const Cat = mongoose.model("Cat", { name: String });

const kitty = new Cat({ name: "Zildjian" });
kitty.save().then(() => console.log("meow"));

I have changed url mongodb://127.0.0.1:27017/test from mongodb://localhost:27017/test and it started working

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM