概要
localhostだと接続できないが127.0.0.1だと接続できるとのこと。
OK
mongodb://127.0.0.1:27017/xxx
import mongoose from 'mongoose'
const connectDB = async () => {
try {
await mongoose.connect('mongodb://127.0.0.1:27017/xxx');
console.log("connected to MongoDB.");
} catch (err) {
console.log("unconnected to MongoDB.");
throw new Error();
}
};
export default connectDB;
NG
mongodb://localhost:27017/xxx
参考サイト
Mongoose can't connect (localhost)
I am trying to connect to my database using mongoose within Apollo-Server-Express. I have created a db in the terminal. I read that 'mongodb://localhost:27017/*db-name *' is the default uri-string ...
コメント