2

Is there a way to use MongoDB authentication in Doctrine MongoDB ODM? equivilant to db.auth(username,password) in shell

Omar
  • 8,374
  • 8
  • 39
  • 50

1 Answers1

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