Solvedmongoose 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

16 Answers

✔️Accepted Answer

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:

mongoose.connect(`mongodb://${encodeURIComponent(username)}:${encodeURIComponent(password)}@localhost:27017/github_issue?authSource=admin`, {
  useMongoClient: true
});