Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mongoose connection with authentication #4891

Closed
nasr18 opened this issue Jan 11, 2017 · 1 comment
Closed

mongoose connection with authentication #4891

nasr18 opened this issue Jan 11, 2017 · 1 comment

Comments

@nasr18
Copy link

nasr18 commented Jan 11, 2017

How do i execute query with authentication enabled?

Yesterday our app's mongodb data was deleted by some scripts. So that we enabled auth in our mongodb. But now i can't able to query the data. How do i enable auth using mongoose?

@sobafuchs
Copy link
Contributor

sobafuchs commented Jan 11, 2017

I normally do it 1 of 2 ways:

  1. Connection string:

mongoose.connect('mongodb://username:password@host:port(usually 27017)/db')

Where username and password are the respective username and password for that specific db, host would be the host where your db is hosted (so localhost or some domain/IP), port is the port mongo listens on, and db is the name of the db you want to connect to

  1. Using options. From the docs:
var options = {
  db: { native_parser: true },
  server: { poolSize: 5 },
  replset: { rs_name: 'myReplicaSetName' },
  user: 'myUserName',
  pass: 'myPassword',
  promiseLibrary: global.Promise
}
mongoose.connect(uri, options);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants