开发者社区> 问答> 正文

MongoDB无法连接

我们购买了阿里云serverless mongodb, 然后在nodejs app里尝试连接这个数据库,但是得到了如下的错误: UnhandledPromiseRejectionWarning: MongoError: not authorized on admin to execute command { createIndexes: "sessions", indexes: [ { name: "expires_1", key: { expires: 1 }, expireAfterSeconds: 0 } ], writeConcern: { w: "majority" }, lsid: { id: UUID("0a16821d-5471-4b26-9479-d4d9f3cbafe9") }, $clusterTime: { clusterTime: Timestamp(1615254942, 3), signature: { hash: BinData(0, 06B4BBD9839B3B77425C4E867DA823FCEB15AAF3), keyId: 6916514152638840862 } }, $db: "admin" }

请问这个错误是什么意思呢?要如何修复呢?

展开
收起
游客fzvopd5s7e3qo 2021-03-09 10:25:38 2723 0
2 条回答
写回答
取消 提交回答
  • 专注于数据库领域技术

    看错误是要在 admin 库中 sessions 表上要创建索引?一般应该没有这个权限的。

    建议看一下应用使用的 用户 和 登录库。

    2021-03-25 15:56:10
    赞同 展开评论 打赏
  • 需要在链接时指定 authentication database: ,如用 mongodb client 时 加入 --authenticationDatabase admin 参数连接。

    2021-03-09 21:54:38
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Data as a Service - 数据即服务 -- MongoDB⾼级应⽤模式 立即下载
阿里云MongoDB云服务构建 立即下载
饿了么高级架构师陈东明:MongoDB是如何逐步提高可靠性的 立即下载