当我试图在连接mongoDB atlas cloud时运行app.js时,它给了我错误。
操作“items.find()”缓冲在10000ms后超时。
与localhost连接时,它工作得很好。
有谁能帮我解决这个问题吗?
//jshint esversion:6
const uri =
"mongodb+srv://****:****@cluster0.tzmxqm3.mongodb.net/?retryWrites=true&w=majority/todolistDB";
// Create a MongoClient with a MongoClientOptions object to set the Stable API version
const client = new MongoClient(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
serverApi: ServerApiVersion.v1,
});
async function run() {
try {
// Connect the client to the server (optional starting in v4.7)
await client
.connect()
.then(() => console.log("connected"))
.catch((e) => console.log(e));
} finally {
// Ensures that the client will close when you finish/error
await client.close();
}
}
run().catch(console.dir);
1条答案
按热度按时间fjaof16o1#
你在末尾指定了数据库的名称,所以你将w参数设置为'majority/todolistDB',这在理论上是不正确的,而是尝试