mongoserverrror: bad auth: authentication failed

编程入门 行业动态 更新时间:2024-10-04 11:24:30

mongoserverrror: <a href=https://www.elefans.com/category/jswz/34/1753124.html style=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

本文发布于:2024-05-30 21:08:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770925.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:bad   mongoserverrror   auth   failed   authentication

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!