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

createConnection does not return a Promise, as it should #11686

Closed
trycoon opened this issue Apr 19, 2022 · 2 comments · Fixed by #11693
Closed

createConnection does not return a Promise, as it should #11686

trycoon opened this issue Apr 19, 2022 · 2 comments · Fixed by #11693
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Milestone

Comments

@trycoon
Copy link

trycoon commented Apr 19, 2022

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

What is the current behavior?
Running createConnection() gives the following error "TypeError: mongoose.createConnection(...).then is not a function"

If the current behavior is a bug, please provide the steps to reproduce.

import mongoose from 'mongoose';
mongoose.createConnection('mongodb://localhost:27017/db', {}).then((db) => {});

What is the expected behavior?
That the function would return a Promise, according to the documentation:
@return {Connection} the created Connection object. Connections are thenable, so you can do await mongoose.createConnection()

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

Mongoose 6.3.0
The problem is this line: https://github.com/Automattic/mongoose/blob/master/lib/index.js#L286
In Mongoose 5.12.3 its working, and then the code reads:

 if (arguments.length > 0) {
    return conn.openUri(uri, options, callback);
  }

  return conn;

It returns the Promise created by openUri()

@trycoon
Copy link
Author

trycoon commented Apr 19, 2022

Could be related to #8706

@trycoon
Copy link
Author

trycoon commented Apr 19, 2022

Ok, I missed this: https://mongoosejs.com/docs/migrating_to_6.html#the-aspromise-method-for-connections
So then this is the expected behavior... But this line should then be removed: "Connections are thenable, so you can do await mongoose.createConnection()"

@IslandRhythms IslandRhythms added the docs This issue is due to a mistake or omission in the mongoosejs.com documentation label Apr 20, 2022
@AbdelrahmanHafez AbdelrahmanHafez added this to the 6.3.1 milestone Apr 20, 2022
vkarpov15 added a commit that referenced this issue Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants