bad auth: authentication failed"/>
mongoserverrror: bad auth: authentication failed
const { MongoClient, ServerApiVersion } = require('mongodb');
const uri = "mongodb+srv://admin:<password>@cluster0.1iafpek.mongodb/?retryWrites=true&w=majority";
// Create a MongoClient with a MongoClientOptions object to set the Stable API version
const client = new MongoClient(uri, {
serverApi: {
version: ServerApiVersion.v1,
strict: true,
deprecationErrors: true,
}
});
async function run() {
try {
// Connect the client to the server (optional starting in v4.7)
await client.connect();
// Send a ping to confirm a successful connection
await client.db("admin")mand({ ping: 1 });
console.log("Pinged your deployment. You successfully connected to MongoDB!");
} finally {
// Ensures that the client will close when you finish/error
await client.close();
}
}
run().catch(console.dir);
我想将本地数据库连接到基于远程云的服务器,但它抛出了错误的身份验证错误,请告诉我哪里做错了。谢谢!
回答如下:更多推荐
mongoserverrror: bad auth: authentication failed
发布评论