Rails Mongoid fails to authenticate - failed with error 13: “not authorized for query on my_db.my_collection”

戏子无情 提交于 2019-11-30 17:45:48
Clayton Selby

Ran into this problem also. I would be willing to guess you are running MongoDB 3+?

The bad news: Moped 2 (which used by mongoid today) does not support authentication for MongoDB 3+.

Moped also falls short on a lot of essential functionality for supporting server version 3.0. For example, it simply doesn’t support authentication with MongoDB 3.0 or recent versions of the wire protocol (which includes commands such as listCollections, listIndexes, and the ability to do bulk writes). Integrating Mongoid with Ruby driver 2.0 will bring a lot of this functionality and forward-compatibility to the ODM. Source

The good news: A major rewrite is underway right now (Mongoid 5), which will be supported by the MongoDB team. You can pull from master today and test it out...but I would not recommend for production yet as it is highly unstable.

Solution options

  1. Remove user/pass auth from MongoDB and any public DNS to the database. Use SSH with a private key and connect to the private address.
  2. Downgrade to MongoDB 2.x
  3. Use Mongoid 5
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!