Skip to content

openUri doesn't flush buffer commands on open (and why createConnection returns a Promise?) #5404

@ValYouW

Description

@ValYouW

mongoose 4.11.0

When using openUri the connection onOpen is not getting called and as a result all collections are in "buffer" mode, maybe the following line should be replaced to _this.onOpen()
https://github.com/Automattic/mongoose/blob/master/lib/connection.js#L739

[Edit] I'll elaborate as I forgot to mention I did a little hack :)
What I was trying to achieve is make createConnection to always return the Connection object, whether it was called with useMongoClient or not. The fact that it returns a Promise is breaking my code as now I need to wait for the Promise to resolve before I can define models on this connection.
So maybe the correct question is "Why createConnection doesn't return the connection but a Promise?", since connection has a buffer mechanism, and it is an emitter that emits an "open" event it make sense to get it immediately (like it was before 4.11.0).

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis issue is a user-facing general improvement that doesn't fix a bug or add a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions