mongoose: the options [user] and [pass] is not supported when using with useMongoClient: true
Do you want to request a feature or report a bug? Bug
What is the current behavior?
When using user
and pass
as a connection option with useMongoClient: true
, it’ll report following warning:
the options [user] is not supported
the options [pass] is not supported
and failed to authenticate.
If the current behavior is a bug, please provide the steps to reproduce.
var mongoose = require("mongoose");
mongoose.connect('mongodb://localhost:27017/github_issue?authSource=admin', {
user: 'username',
pass: 'password',
useMongoClient: true
});
let issueSchema = new mongoose.Schema({
'str' : { type: String }
});
issueModel = mongoose.model('issues', issueSchema );
issueModel.find({}, function(err, issueList){
if(err)
throw err;
console.log(issueList);
});
Log:
the options [user] is not supported
the options [pass] is not supported
{ MongoError: not authorized on users to execute command { find: "customers", filter: {}, projection: {} }
at Function.MongoError.create (<PROJECT_PATH>\node_modules\mongodb-core\lib\error.js:31:11)
at queryCallback (<PROJECT_PATH>\node_modules\mongodb-core\lib\cursor.js:212:36)
at <PROJECT_PATH>\node_modules\mongodb-core\lib\connection\pool.js:469:18
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
name: 'MongoError',
message: 'not authorized on users to execute command { find: "customers", filter: {}, projection: {} }',
ok: 0,
errmsg: 'not authorized on users to execute command { find: "customers", filter: {}, projection: {} }',
code: 13,
codeName: 'Unauthorized' }
What is the expected behavior? It should just report the result in the collection to the console.
[{
str: 'Test'
}]
Please mention your node.js, mongoose and MongoDB version. Node: v6.10.0 MongoDB: 3.4.5 on the offcial Mongo docker container Mongoose: 4.11.0
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 6
- Comments: 15
Commits related to this issue
- Update Mongoose user/pass handling and option format See: https://github.com/Automattic/mongoose/issues/5419 — committed to frib-high-level-controls/swdb by dxmaxwell 7 years ago
Working on getting support for this in the mongodb driver with the above PR ☝️ . For now, as a workaround, put username and password into the URI:
2.2.31 is out which includes mongodb/node-mongodb-native#1529 🎉
Nope it encodes the string for use in a uri. Escaping /, :, and other special characters
When I do the “work-around” I get authentication failed, but if I leave the user/pass options in the authentication works.
-edit: nevermind, I didn’t know I had to specify db also