Is there a way to use MongoDB authentication in Doctrine MongoDB ODM? equivilant to db.auth(username,password) in shell
Asked
Active
Viewed 1,000 times
1 Answers
4
The most robust method is to specify your username and password in the connection URI (e.g. mongodb://username:password@localhost
), as that will allow the driver to re-authenticate if a connection is dropped and it needs to reconnect. You can also use MongoDB::authenticate() if you need to authenticate against various DB's in a single connection, but you will have to manually re-authenticate if the connection is dropped. See the connection documentation for more examples.

jmikola
- 6,892
- 1
- 31
- 61