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

MongoParseError: credentials must be an object with 'username' and 'password' properties #10726

Closed
saveman71 opened this issue Sep 15, 2021 · 2 comments · Fixed by #10727
Closed
Milestone

Comments

@saveman71
Copy link
Contributor

saveman71 commented Sep 15, 2021

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

As described in https://mongoosejs.com/docs/connections.html#options:

let connect = mongoose.connect('mongodb://localhost:27018/test', {
	user: 'admin',
    pass: 'password',
});

Should forward the auth to the nodejs driver. Looking at the object sent to the driver:

{
  authSource: 'admin',
  auth: { user: 'admin', password: 'password' },
  driverInfo: { name: 'Mongoose', version: '6.0.5' }
}

Looking at https://github.com/mongodb/node-mongodb-native/blob/4.0/docs/CHANGES_4.0.0.md#authentication, it says the expected format is username and not user, as the error suggests:

MongoParseError: credentials must be an object with 'username' and 'password' properties.

Noting that the following works:

let connect = mongoose.connect('mongodb://localhost:27018/test', {
	auth: {
		username: 'admin',
		password: 'password',
	}
});

Either the doc need to be updated to remove the user/pass backwards compat (which appears broken) or it needs to set username instead of user in the auth object.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

MongoDB 3.4
Mongoose 6.0.5
NodeJS v14.17.6

Here is the code responsible for the bug:

mongoose/lib/connection.js

Lines 742 to 750 in e6820ee

// Backwards compat
if (options.user || options.pass) {
options.auth = options.auth || {};
options.auth.user = options.user;
options.auth.password = options.pass;
this.user = options.user;
this.pass = options.pass;
}

@im-ghost
Copy link

im-ghost commented May 6, 2022

Still doesn't seems to work well here,despite putting it as an object
Auth:{username:""}

@vkarpov15
Copy link
Collaborator

@Peculiar-codes open a new issue and follow the issue template please

@Automattic Automattic locked and limited conversation to collaborators May 27, 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

Successfully merging a pull request may close this issue.

3 participants