MongoError: not authorized on admin to execute command on AWS Lightsail

MongoError: not authorized on admin to execute command on AWS Lightsail

我正在尝试将我的应用程序部署到 AWS Lightsail。但是,我运行 进入这个错误:MongoError: not authorized on admin to execute command { listIndexes: "users", .....。服务器 运行 正在使用 Bitnami MEAN 堆栈版本 3.6.5-0。我在创建服务器时遵循了this tutorial。我创建了一个数据库,切换到它,并创建了连接字符串为:mongodb://user:pwd@localhost:27017/?authMechanism=SCRAM-SHA-1&authSource=database 的 .env 文件。

应用程序说它连接到数据库,然后立即抛出上述错误并使整个应用程序崩溃。根据我的发现,这似乎与我为其创建的数据库用户的角色有关。数据库用户具有 "dbOwner" 的角色,根据教程和 MongoDB 文档应该没问题。

我尝试了多种不同的解决方案,包括更改用户角色、更改连接字符串等。 None 到目前为止,其中对我有用。我很感激这方面的一些帮助,因为我已经坚持了好几天了。谢谢。

我解决了这个问题。问题出在我的连接字符串中。该字符串显然是出于测试目的而硬编码的,并且从未改回。

解决方案是mongodb://user:pwd@localhost:27017/database?authMechanism=SCRAM-SHA-1&authSource=database