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.
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.