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

How to specify --authenticationDatabase in mongoose? #3905

Closed
SamuelMarks opened this issue Feb 23, 2016 · 7 comments
Closed

How to specify --authenticationDatabase in mongoose? #3905

SamuelMarks opened this issue Feb 23, 2016 · 7 comments

Comments

@SamuelMarks
Copy link

Works in the shell:

$ mongo -u monguser -p mongpass 192.168.2.2/ps --authenticationDatabase=admin
MongoDB shell version: 3.2.3
connecting to: 192.168.2.2/ps
Server has startup warnings: 
2016-02-23T01:59:10.522+0000 I CONTROL  [initandlisten] 
2016-02-23T01:59:10.522+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-02-23T01:59:10.522+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-02-23T01:59:10.522+0000 I CONTROL  [initandlisten] 
2016-02-23T01:59:10.522+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-02-23T01:59:10.522+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-02-23T01:59:10.522+0000 I CONTROL  [initandlisten] 
> db.foo.insert({can:'haz'})
WriteResult({ "nInserted" : 1 })

Fails in mongoose:

'use strict';

const mongoose = require('mongoose');

const uri = 'mongodb://monguser:mongpass@192.168.2.2:27017/ps'

console.log('mongoose.connect =', mongoose.connect(uri, (err) => {
    err && console.log('err =', err);
}));
// For `mongoose.connect` output, see: https://gist.github.com/SamuelMarks/dedd863742f90cf2f333
err = { [MongoError: Authentication failed.]
  name: 'MongoError',
  message: 'Authentication failed.',
  ok: 0,
  code: 18,
  errmsg: 'Authentication failed.' }

So it's save to assume that authenticationDatabase needs to be set somehow, maybe in the config parameter. What's the syntax?

@vkarpov15
Copy link
Collaborator

Easiest way is to specify authSource in the uri

const uri = 'mongodb://monguser:mongpass@192.168.2.2:27017/ps?authSource=admin';

@vkarpov15
Copy link
Collaborator

See mongodb connection string docs

@SamuelMarks
Copy link
Author

Thanks

@mhassanist
Copy link

@vkarpov15 you saved my day. Thanks a lot.

@ORESoftware
Copy link

ORESoftware commented Jul 28, 2017

Anybody know how to specify authSource when using mongodump command? :]

@vkarpov15
Copy link
Collaborator

@ORESoftware mongodump calls it authenticationDatabase: https://docs.mongodb.com/manual/reference/program/mongodump/#cmdoption-authenticationdatabase

@liudonghua123
Copy link

If /defaultauthdb and ?authSource=admin both specified, then /defaultauthdb will be the database you tried to connect?

For const uri = 'mongodb://monguser:mongpass@192.168.2.2:27017/ps?authSource=admin';, the database connected is ps.

https://www.mongodb.com/docs/manual/reference/connection-string/#components

@Automattic Automattic locked and limited conversation to collaborators Dec 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants